tags:

views:

20

answers:

2

Hello all,

I designed a form as follows:

User Name: _______________
Password:  _______________

   Login

I also use jQuery Form Plugin to submit the form to the server side. It will return if the server script finds some errors. The data returned by server is in JSON format. I would like to know how I can reset the user name + password when I know the username/password is invalid in a decent way.

In other words, I can manually use jQuery to empty the username/password field if the returned result indicates a failure. In fact, I am looking for a decent way built in Form Plugin or sth else that can do this part me for automatically. The only thing I have to do is to set a flag so that if the submission is failed, then the form will be resetted.

Thank you

+3  A: 

You cam simply do:

$('#form_id').reset();

I don't think you need a plugin for such simple task. You simply call above code based on the response.

+1  A: 

Run this.form.reset() when a form button (e.g. Reset) is being pressed.

e.g.

<form>
...
<input type="button" value="Reset!" onclick="this.form.reset();">
</form>
thelost