user3765800
user3765800

Reputation: 27

Jquery reset form no erase fields

I need erase or empty input fields of form i use this but no works :

<script>
jQuery(document).ready(function() 
{
jQuery("#contact_form").get(0).reset()  
});
</script>

<form id="contact_form" name="form" method="post" action="">

<input name="c_name" type="text" title="Insert Personal Name" value="Personal Name" />

</form>

The script must erase the content of input text and no show the text Personal name , the case it´s no works and no reset the form

I dont know if exists some error but i think must works

Thank´s , Regards

Upvotes: 0

Views: 135

Answers (1)

Shaunak D
Shaunak D

Reputation: 20626

You cannot reset a form with input value defined by using inline attribute, use .val()

Demo

$("#contact_form input[name=c_name]").val('');

Or add a button, and reset form on click event of it.

Demo

$("button").click(function(){
    $("#contact_form")[0].reset();
});

Note : reset() changes the value of input to its inital value (in your case it will reset to Personal Name.

Upvotes: 1

Related Questions