2

Hi guys i want to reset(to old) the values of multiple text boxes when i click on check box. please help

2
  • more information please, and code appreciated Commented Feb 1, 2011 at 8:38
  • wich value do you want to change? the value off the clicked input element? Commented Feb 1, 2011 at 8:38

2 Answers 2

2

I guess you mean restore the original values of the textboxes? If so, here is the required code:

<script type="text/javascript">
function RestoreValues() {
   var arrInputs = document.getElementsByTagName("input");
   for (var i = 0; i < arrInputs.length; i++) {
       var oCurInput = arrInputs[i];
       if (oCurInput.type == "text")
           oCurInput.value = oCurInput.defaultValue;
   }
}
</script>

To restore the values just call the function, for example:

<button type="button" onclick="RestoreValues();">Restore</button>

Live test case: http://jsfiddle.net/yahavbr/Nakjv/2/

Edit: using defaultValue save lots of code. :)

Sign up to request clarification or add additional context in comments.

Comments

2

In Javascript you can restore a default value of an input field like this:

var myinput = document.getElementById("myinput");
myinput.value = myinput.defaultValue;

HTH

4 Comments

Forgot about defaultValue! :)
@Shadow\ Wizard - sweet. that is handy!
@Joe yes indeed! BTW using @ you have to omit any spaces so if using the full name it's @ShadowWizard but first three letters are enough so @Sha will work as well. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.