0

I have a page which has a form with a few validators. I also have a button (HTML submit) which resets form and clears all textboxes. The code works fine the first time I click the button, which clears the form. But if I refill the form and try to clear the form for the second time, it won't work. I also have other jQueries to toggle areas of code, they also stop working after this.
One thing to mention is that when I press clear form button, asp validators show themselves, which is odd to me because I have not put a validationGroup on them and not on my button. I think this happens because the button tries to do a postback.
So two questions, first what's causing my queries not to work?
And second, how do I stop the button from attempting to post back (which causes validators to be shown)?
The code looks something like this:

<script>
  scripts clearing the form and doing toggle actions here.
</script>
<form>
  label & texbox pairs to get info from user, accompanied by Required field validators.
  <asp:Button ... The Button to submit form />
  <input typ="submit" value="Clear Form" /> -->The button to clear form on client side.
</form>
3
  • In case there may be other causes to your problem, please post actual code. Commented Aug 21, 2011 at 18:27
  • actual code is pretty big, is there a place I can upload it and give the link? But I still put it. Commented Aug 21, 2011 at 18:30
  • you can try jsfiddle.net but I am not sure how big it can handle. Commented Aug 21, 2011 at 18:33

1 Answer 1

1

This will stop the submit -- add a return false.

 $('#btnResetForm').click(function () {
            $('#<%=txtFname.ClientID %>' +
            ',#<%=txtLname.ClientID %>' +
            ',#<%=txtNatNo.ClientID %>' +
            ',#<%=txtBirthCertNo.ClientID %>' +
            ',#<%=txtUsername.ClientID %>' +
            ',#<%=txtCellNo.ClientID %>' +
            ',#<%=txtPhoneNo.ClientID %>'
            ).val("");
            return false;
        });

You might want to use toggle() and not show and hide to let buttons keep working.

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

8 Comments

they're not buttons that do toggle, they're actually radion buttons that make different areas diplayed and hidden.
I only speak english so I'm having trouble with what you are trying to do... sorry.
The controls that do hide/show actions are not buttons. They are radiobuttons as you may see in the code. Each radio buttons shows several areas of code and hides others. So it isn't exactly toggling, and I can't use toggle function. (It's not causing any problem any ways, but thanks for the advice).
You can enclose groups of controls in a div and then call .toggle() on that div -- maybe that makes it easier?
Not an option, what if a radio button is click two times?
|

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.