Link to home
Start Free TrialLog in
Avatar of SurreyWebDesigner
SurreyWebDesigner

asked on

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
Avatar of archrajan
archrajan

<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");
u can also use the defaultValue property

if(document.getElementById('txt').value == document.getElementById('txt').defaultValue)
alert("same");
Avatar of SurreyWebDesigner

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of archrajan
archrajan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent - that worked ... thanks!

Very quick response by the way - cheers!
u r welcome and thanks for the grade and the sweet compliments!