How to get my onsubmit to fire before my onclick event?

Hi, I have a form that as a C# onclick event, and an onsubmit event for javascript:

        <form method="post" action="user.aspx" id="LoginForm" onsubmit="listErrors(&#35;LoginForm)" runat="server" visible="false">
            <label>Email<span class="red">*</span></label>
            <asp:TextBox id="loginEmail" value="" class="form-text" runat="server" />
            <label>Password<span class="red">*</span></label>
            <asp:TextBox id="loginPassword" value="" class="form-text" runat="server" />
            <br />
            <asp:Button text="Log In" class="form-submit" runat="server" OnClick="LogIn" />
        </form>

Open in new window


Unfortunately, when the submit (Log In button) is clicked the C# function is executed before my javascript function. If the javascript function were executing it would alert the form name.

(its the first form only before any of the other tabs have been clicked. Once a tab is clicked the javascript function listErrors() is activated in a different way)
http://auroriella.com/user.aspx#login

Any suggestions?
FairyBusinessAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Add quotes arround any string (simple quotes in your case) :

listErrors('#LoginForm')

Open in new window


and place your alert before to "debug":
// blank errors
function listErrors(form) {
        alert(form); // here
    $(form).submit(function () {
        $("#error").empty();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FairyBusinessAuthor Commented:
oddly enough my alert is going off now, but its like its ignoring the rest of my jquery code and moving on to my C# function!

Which I don't even know how that can be firing bc there is no longer an onlick="LogIn" on that submit button. . . its quite mysterious to me lol
0
leakim971PluritechnicianCommented:
yes, use : $("form")
instead : $(form)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

FairyBusinessAuthor Commented:
For what? the alert??
0
leakim971PluritechnicianCommented:
no, check line 4 ID:37377746, this is a part of your code
0
FairyBusinessAuthor Commented:
but form is a variable, holding the form's #id. why would I use "form" ??  What does $("form") stand for?
0
FairyBusinessAuthor Commented:
<form id="LoginForm" onsubmit="listErrors('#LoginForm')" action="user.aspx" method="post">

Open in new window

0
leakim971PluritechnicianCommented:
>but form is a variable, holding the form's #id. why would I use "form" ??  What does $("form") stand for?

Ok, in this case it's about your selector (your other question) and initialy the missing the quotes (my first post)
0
FairyBusinessAuthor Commented:
I added the quotes but its still not working.  What about a selector for this question?

(for the other question I decided to accept your solution)
0
leakim971PluritechnicianCommented:
Modify your alert to :
// blank errors
function listErrors(form) {
        alert($(form).length); // if you've zero in the alert, the selector is not the right one
    $(form).submit(function () {
        $("#error").empty();

with the quotes, it work but the selector is not good to do what you want I don't know why

0
FairyBusinessAuthor Commented:
it alerts the number 1

I have no idea why. . . . I mean this is what it looks like in the source code:

<form id="LoginForm" onsubmit="listErrors('#LoginForm')" action="user.aspx" method="post">

Open in new window


how can #LoginForm turn into the number 1???????????

(click the Log In button)
http://auroriella.com/user.aspx
0
leakim971PluritechnicianCommented:
$.submit allow you to bind for submit event.
assuming the event is already fired, it's to late to bind it, you may not need : $(form).submit(function () {
http://api.jquery.com/submit/


0
FairyBusinessAuthor Commented:
Ok, I decided to call the function in my $(document).ready(function () bc I was already called the submit twice.

   
listErrors("#LoginForm");

Open in new window


thanks for your help again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.