Sam
Sam

Reputation: 4339

Issue resetting form with JQuery

I'm having an issue with a form that is built with Ajax. Basically it is one of those forms which populates as you drill down from a parent select. The problem is once you advance forward a page, and go back the first drop down has its option selected, but the others are not processed and therefore just say "Select a [thing] first". So I'm trying to reset the form when I move back a page.

I have in my document ready the following:

$('form[name="Search"]')[0].reset();

This works fine in Firefox and Chrome, however IE9 I get the following message:

Microsoft JScript runtime error: Unable to get value of the property 'reset': object is null or undefined

Does anyone know of a workaround, or suggest a better way to approach this?

Thanks.

Upvotes: 0

Views: 1325

Answers (1)

Sam
Sam

Reputation: 4339

Okay, I did some more thinking about this and used the horrid developer tools in IE.

Turns out that when I hit back, for some stupid reason IE blows away the ID and Name attributes of the . Therefore, I changed the jQuery to:

$('form[action="{posturl}"]')[0].reset();

That works fine.

Upvotes: 1

Related Questions