Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset Particular Input Element in a HTML Form

Tags:

html

forms

reset

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.

like image 701
SKR Avatar asked Apr 22 '10 09:04

SKR


People also ask

How do you reset input in HTML?

The <input type="reset"> defines a reset button which resets all form values to its initial values.

How do you reset input element?

The HTMLFormElement. reset() method restores a form element's default values. This method does the same thing as clicking the form's <input type="reset"> control. If a form control (such as a reset button) has a name or id of reset it will mask the form's reset method.

How do I add a reset button to a form?

Type the <input type="reset"> tag into the code towards the top and/or bottom of the HTML form. Close the form after all input fields are entered with a final </form> tag. Save and preview your new adjusted form with the new reset button.

Is reset an input type?

The reset input type creates a button that resets the form to the default values. If the value attribute is present, the value of that attribute will be the text on the button. If not, the default wording on the reset button is “Reset”.


1 Answers

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).

like image 168
bobince Avatar answered Oct 22 '22 09:10

bobince