How to dynamically add an onclick event to a submit button?

Hi, I am trying to add an onclick event to one of my form submit button's:

example:
$("input:submit", this).attr("OnClick", "SignUp");

Open in new window


But its not working. I am doing this for C# not for javascript (I would not need to dynamically add this onclick event for a javascript function).

Does anyone know how to do this??
FairyBusinessAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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:
$("input:submit", this).click(SignUp);

Open in new window

0
FairyBusinessAuthor Commented:
I don't think the .click works on calling C# functions.  It really does need to appear in my code like so:

<input class="form-submit" type="submit" value="Log In" onclick="LogIn">

Is there anywhere to do that thru jquery??
0
leakim971PluritechnicianCommented:
Oh, you mean SignUp is a C# function?

Check this article for example : http://www.dotnetcurry.com/ShowArticle.aspx?ID=109
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

FairyBusinessAuthor Commented:
Well, I'm not familar with ajax yet.  But I'll look at that article more later.

Do you know of any way just to add an onclick event thru jquery (regardless of what language its for)?
If it said onclick="LogIn" then my C# code would work.  Thats all I need it to do. ..
0
leakim971PluritechnicianCommented:
With PageMethods, you don't need to be familiar with Ajax (but you know the process is ajax based)
0
leakim971PluritechnicianCommented:
Javascript calling the SignUp function :
PageMethods.SignUp(ctrl.value, CallSuccess, CallFailed, dest);
0
FairyBusinessAuthor Commented:
You know, I tried do this:

       
 $(".form-submit", this).attr("id", "love");

Open in new window


but it didn't add that attribute to it either. Do you see any reason why the .attr isn't working on my submit buttons??

Where would this piece of code go??

PageMethods.SignUp(ctrl.value, CallSuccess, CallFailed, dest);
0
leakim971PluritechnicianCommented:
>but it didn't add that attribute to it either.
You may not see it and/or the selector is not good

>but it didn't add that attribute to it either.
You need to read the article, basically anywhere you want to call your C# function (SignUp)
0
FairyBusinessAuthor Commented:
For this article you gave me I have to download ajax extensions and it seems like a lot of code for one thing.  I really would rather just focus on getting my .attr to work.   If I can't get the .attr with any attribute I have a real problem.  How could the selector not be good?
0
FairyBusinessAuthor Commented:
Ah, I figured it out.  The problem was I thought I could use this inside of an if statement and it would take on the value of the condition of the if statement.

    if ($("#LoginForm").length > 0) {
        $("input:submit", "#LoginForm").attr('OnClick', 'LogIn');
        form = "#LoginForm";
    }

Open in new window


I got rid of the this and replaced it by the actual code.
0
FairyBusinessAuthor Commented:
I've requested that this question be deleted for the following reason:

The problem was my syntax, nothing really related to my question.
0
leakim971PluritechnicianCommented:
>but it didn't add that attribute to it either.
You may not see it and/or the selector is not good
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:
I have decided to accept a solution to this question.
0
FairyBusinessAuthor Commented:
thanks
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.