You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Kumar, Sandy" <SK...@npc.net> on 2005/12/21 23:26:14 UTC

To check whether jsp form elements have changed

All,
 
 I have a page with 3 tabs. If user goes to any of the pages, and does
not alter the value he entered before, I should not submit the form.
 
How can I check whether jsp form elements have changed or not?.
 
Thanks,
Sandy Kumar

Re: To check whether jsp form elements have changed

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I'm not sure there's any especially good way... the methods I can think 
of all require scripting of some sort.  If that is OK though...

First, I would store the original value in some way, preferably as part 
of the form element... I assume your using the HTML taglib, so one 
candidate might be to use the alt attribute... if you aren't using tht 
HTML taglib, you can simply set some arbitrary attribute of the element, 
that works great... then, use EL to populate the alt attribute (or your 
own attribute) with the value of the field.

Alternatively, render some Javascript that stores the values in an 
associative array.  This would work regardless of the taglib you use, if 
any.

Then, I would create a Javascript function which is called when your 
form is submitted... this function would go through all the elements of 
your form and compare their current values to their original values.  If 
any don't match, your data is "dirty", and you need to save.

Another method is to include an onChange event handler for every element 
in your form that sets a flag to indicate the data is "dirty".  Then you 
just check that flag on submit.  The problem with this is it isn't 
guaranteed accurate... if the user alters a field, then re-enters the 
original value, it'll still be flagged as "dirty" data.  I've done this 
frankly, and it is usually OK with people, but not always.

Kumar, Sandy wrote:
> All,
>  
>  I have a page with 3 tabs. If user goes to any of the pages, and does
> not alter the value he entered before, I should not submit the form.
>  
> How can I check whether jsp form elements have changed or not?.
>  
> Thanks,
> Sandy Kumar
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org