0

I have built a web form with some tables and custom controls inside it, and now I would like to provide a button to clear all the fields (radio buttons included). Since I had never worked with jQuery before, and since I read somewhere it can save a lot of work and has a consistent behaviour with most browser, I thought about using it with the jquery.form.js plugin to clear the form in an easy way. I renamed the form to

<form id="someForm" action="~/Default.aspx"> (...) </form>

and on the OnClientClick event of the button I wrote

$form('#someForm').clearForm();

The problem is that nothing really happens... jQuery is properly referenced, since

$(document).ready(function() { alert('Test'); });

shows the alert dialog properly, but the previous command doesn't really do anything. Then I tried using the standard

document.forms[0].reset();

and it works fine. I know about the "problems" with this command, since it doesn't really clear all the fields but rather resets it to their original state... In the particular case of this form the two effects are really the same, but I would like to know why jQuery is not working in the case of this form. Does anyone have any ideas?

2 Answers 2

1

It should be: $('#someForm').clearForm();

Sign up to request clarification or add additional context in comments.

Comments

1

just the duplicate of answer by scrappedcola

$('#someForm').clearForm();

is the way to select the form by id see jquery selectors

2 Comments

The op doesn't need to roll his own function as the plugin he has already has a clearForm function: jquery.malsup.com/form
oops! i got carried away while writing the answer you are rite

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.