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?
 
leakim971PluritechnicianCommented:
>but it didn't add that attribute to it either.
You may not see it and/or the selector is not good
0
 
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
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.

 
leakim971PluritechnicianCommented:
Oh, you mean SignUp is a C# function?

Check this article for example : http://www.dotnetcurry.com/ShowArticle.aspx?ID=109
0
 
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
 
FairyBusinessAuthor Commented:
I have decided to accept a solution to this question.
0
 
FairyBusinessAuthor Commented:
thanks
0
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.

All Courses

From novice to tech pro — start learning today.