Javascript form elements defaultstate

M

msforme

Hi ,

Is there some way by which I get to know if the state of my form
elements have changed or not ? I mean If I have to save data which has
been entered by user in the screen, Is there some way in the JS level
that I am able to check (before i pass information to java) if the
value of the form element is same or different from the time the page
had loaded ?

So ill be able to selelct and save only those elements whose values
have been changed

I am dealing with text boxes and drop downs . .

thanks
 
S

sunilp

You can check defaultValue/defaultChecked value of element.

if(elem.defaultValue != elem.value) {
//elem value is changed.
}
 
M

Matt Kruse

Is there some way by which I get to know if the state of my form
elements have changed or not ?

My lib at http://www.JavascriptToolbox.com/validations/ has an isChanged()
function which can tell you if an input of any time has been changed from
its initial state.
So ill be able to selelct and save only those elements whose values
have been changed

This is not a good idea.
Instead, submit everything, and have your server-side code check against
what is already in the database and save only the changed items.
Marking fields as 'dirty' on the client side works, but ultimately is not as
bullet-proof as handling all that logic on the server side.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,063
Latest member
StormyShuf

Latest Threads

Top