Categories

.formClear()

Categories: Attributes, Tree Traversal | Forms

.formClear()Returns: jQuery

Plugin: jQuery.fn.form

Description: Clear the value of each inputs and inputs of the first form element of matched elements.

  • .formClear()

    version added: 1.0

This method provides to clear value or uncheck one or more inputs, or inputs of a complete form.

The .formClear() empty the value for each input, select and textarea and each input, select and textarea of first matched form.

For <input type="radio"/> or <input type="checkbox"/>, the element will unchecked and the value will not be empty, same works for <select>...</select> the selected <option/> will unselect and the value will not be empty.

  • Clear form elements.

    HTML:
    <div>
      <form id="form_1">
        <input type="radio" name="A" value="1"/>
        <input type="radio" name="A" value="2"/>
        <input type="checkbox" name="B" value="1"/>
        <input type="checkbox" name="B" value="2"/>
        <input type="text" name="C"/>
        <textarea type="text" name="D"></textarea>
      </form>
      <form id="form_2">
        <input type="radio" name="A" value="2"/>
        <input type="radio" name="A" value="3"/>
        <input type="checkbox" name="B" value="2"/>
        <input type="checkbox" name="B" value="3"/>
      </form>
    </div>
    Code:
    $(':checkbox').formReset();
    // reset all input type checkbox
    
    $('#form_2,textarea').formReset();
    // reset all inputs form_2 and the textarea of form_1