Check if field value is modified

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ananth
    New Member
    • Nov 2006
    • 75

    Check if field value is modified

    Hi All,
    I have a text field in my HTML page which has a value stored in it.

    I need a java script code to allow the user to save if the content of the text field is edited.ie User should be prompted with a message on clicking the button
    Displaying the "Content of the field is Edited".

    Please help me in this regard as it will be help ful for my project completion?

    Thanks in Advance!!!!!!!! !
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, ananth.

    Simply store the previous value in the Element object (or a global variable, if you prefer) as the User edits it, then compare it to the current value when the User clicks the button.

    Comment

    • Logician
      New Member
      • Feb 2007
      • 210

      #3
      Originally posted by ananth
      Hi All,
      I have a text field in my HTML page which has a value stored in it.

      I need a java script code to allow the user to save if the content of the text field is edited.ie User should be prompted with a message on clicking the button
      Displaying the "Content of the field is Edited".
      Read the element's defaultValue property.

      Comment

      • ananth
        New Member
        • Nov 2006
        • 75

        #4
        Originally posted by pbmods
        Heya, ananth.

        Simply store the previous value in the Element object (or a global variable, if you prefer) as the User edits it, then compare it to the current value when the User clicks the button.

        Hi pbmods,
        Thanks for your reply ,but do you have any sample code on how to implement it.Any sample code or website links would be of more helpful to me.

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by ananth
          Hi pbmods,
          Thanks for your reply ,but do you have any sample code on how to implement it.Any sample code or website links would be of more helpful to me.
          Have a look at this!
          [code=html]
          <body onload = store()>
          <input type = text id = text1 value = "some_value ">
          <input type = button value = "Check" onclick = "check()">
          </body>
          [/code]

          [code=javascript]
          var prev_value = "";
          function store()
          {
          prev_value = document.getEle mentById('text1 ').value
          }
          function check()
          {
          var cur_value = document.getEle mentById('text1 ').value
          if(cur_value != prev_value) alert("Value changed");
          else alert("Value not changed");
          }
          [/code]

          Good Luck!

          Kind regards,
          Dmjpro.

          Comment

          Working...