Skip to content Skip to sidebar Skip to footer

Clear Or Reset Button

I have a form and a working reset button. When i click the button all inputs and text area boxes are clear. I was wondering if there's a way to create a clear/reset button that wil

Solution 1:

Here's the jsfiddle solution.

<form>
    <input type="text" class="clearit" /><br />
    <input type="text" class="clearit" /><br />
    <input type="text" class="clearit" /><br />
    <textarea id="t5"></textarea><br />
    <input type="reset" id="reset" />
</form>


$(document).ready(function(){ 
    $('#reset').on('click',function(e){
        e.preventDefault();
        $('.clearit').val("");
    });

});

Solution 2:

Assign all input elements a class let suppose inputs and different ids let suppose the id of text area is text_area.

<input type  = "textarea " id = "textarea ">

Now with jquery

$(function(){
   $('.inputs').each(function()
   {
        var id = $(this).attr('id');
         if(id == 'textarea '){

         }else{
           $(this).attr('value',"");
         }
   });
})

Done!


Solution 3:

See the link

http://www.javascript-coder.com/javascript-form/javascript-reset-form.phtml

Basically rather than calling a form.reset() from the reset button, call an external function which clears out the fields you require and leave the remaining as it is.

Hope it solves your problem!


Post a Comment for "Clear Or Reset Button"