Hi guys i want to reset(to old) the values of multiple text boxes when i click on check box. please help
2 Answers
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. :)
Comments
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
@Joe yes there is and it's even cross browser. msdn.microsoft.com/en-us/library/ms533718(VS.85).aspx and developer.mozilla.org/En/XUL:Property:defaultValue
Joe Hanink
@Shadow\ Wizard - sweet. that is handy!