I have multiple input textboxes in my page. I want to reset particular text box to its onload state if certain conditions fails. I am considering using a Hidden element to store the onload state of the textbox. I would other suggestions or solutions to resolve this issue.
A:
That's pretty much the only way you can reset a single control - store the original value and set it back when resetting that specific control.
Oded
2010-04-22 09:42:02
A:
defaultValue
:
<input type="text" value="initial" id="field">
<button id="reset">reset</button>
<script type="text/javascript">
document.getElementById('reset').onclick= function() {
var field= document.getElementById('field');
field.value= field.defaultValue;
};
</script>
Available on text
, password
and textarea
, plus defaultChecked
on checkbox
/radio
and defaultSelected
on option
. Curiously, not available on hidden
(except in IE, where it's considered a bug).
bobince
2010-04-22 09:45:33
Cheers mate, It worked!!!! :-)
SKR
2010-04-22 10:15:49
A:
Oded is right. This is the only way if you are only using html/js. With php/asp.net you could use some sort of global variable or a session variable to store the state.
Quaze
2010-04-22 09:45:45