?
Solved

javascript to check if the contents of a textbox has changed

Posted on 2005-05-05
6
Medium Priority
?
418 Views
Last Modified: 2008-03-03
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
0
Comment
Question by:SurreyWebDesigner
  • 4
  • 2
6 Comments
 
LVL 25

Expert Comment

by:archrajan
ID: 13934960
<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
 
LVL 25

Expert Comment

by:archrajan
ID: 13934980
u can also use the defaultValue property

if(document.getElementById('txt').value == document.getElementById('txt').defaultValue)
alert("same");
0
 

Author Comment

by:SurreyWebDesigner
ID: 13935073
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Accepted Solution

by:
archrajan earned 1000 total points
ID: 13935117
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
 

Author Comment

by:SurreyWebDesigner
ID: 13936519
Excellent - that worked ... thanks!

Very quick response by the way - cheers!
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13936563
u r welcome and thanks for the grade and the sweet compliments!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question