0

I have a form that I am working with, and I am trying to clear it after successful submission using something like this:

$(':text, :password, :file, SELECT', '#create_problem').val('');

The id of my form is create_problem and the elements there are a text box and a check box and a text field.

The code above does nothing to help clear the form. Is it not right?

Thanks!

To reproduce the problem: you can visit: http://www.problemio.com and login with the test account:

login: testuser
password: testuser

and try to add a problem to see that the form does not clear.

GeekedOut
  • 16,905
  • 37
  • 107
  • 185

2 Answers2

3

Just use the built in reset() method of the form element itself:

$("#MyForm").get(0).reset();
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
1
$(':input, :file', '#create_problem')
     .not(':button, :submit, :reset, :hidden')
     .val('')
     .removeAttr('checked')
     .removeAttr('selected');
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • 1
    After http://stackoverflow.com/questions/680241/blank-out-a-form-with-jquery/680252#680252 and N.B. http://stackoverflow.com/questions/680241/blank-out-a-form-with-jquery/3682131#3682131 – agtb Oct 16 '11 at 16:07