javascript to check if the contents of a textbox has changed

Is there a way of telling whether the contents of a textbox has been changed when the user hits the submit button on a form?

I have a list of dates which the user can change - at present it updates my database with all of the data from all of the textboxes.

I only want it to update the data that has actually been changed.

I've tried doing this with ASP but it hasn't worked - so I'm wondering if I can do something clever with JavaScript that means the database only gets updated with data that has actually changed.

Any ideas?

Cheers
SWD
SurreyWebDesignerAsked:
Who is Participating?
 
archrajanConnect With a Mentor Commented:
yeah definitely then u shud have this
<form name = "frm">
<input type = "text" name = "txt" value = "expertsexchange" onchange = "if(this.value != this.defaultValue)document.frm.hid.value = this.value; else document.frm.hid.value = '';">
<input type = "hidden" name = "hid">
</form>
0
 
archrajanCommented:
<input type = "text" value = "something" value1= "something" name = "txt" id = "txt">

now value1 attribute will have the original value

so u can check it like


var temp = document.getElementById('txt').getAttribute('value2')
if(document.getElementById('txt').value == temp)
alert("same");
0
 
archrajanCommented:
u can also use the defaultValue property

if(document.getElementById('txt').value == document.getElementById('txt').defaultValue)
alert("same");
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
SurreyWebDesignerAuthor Commented:
so maybe i could incorporate one of these into a solution that i could use. i was thinking that perhaps i could do it so that when the value in the textbox now is different to the original value then the value of a hidden field gets changed. Then I update the database only with the values from the hidden fields.

Would this work?

I'm not sure on the syntax - could you point me in the right direction?

Cheers
SWD
0
 
SurreyWebDesignerAuthor Commented:
Excellent - that worked ... thanks!

Very quick response by the way - cheers!
0
 
archrajanCommented:
u r welcome and thanks for the grade and the sweet compliments!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.