Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Programmatically click a button using JavaScript (on an ASP.net-based website)

Posted on 2011-10-16
3
Medium Priority
?
256 Views
Last Modified: 2012-05-12
I have an ASP.net (VB) website.  I need to create a JavaScript function that would mimic the act of clicking an image button -- i.e. activate the subroutine that is triggered by clicking the button.

Here is the ASP.net code for the button.  As you can see, clicking the button activates the "GoCheckout" subroutine.  That is what I need a JavaScript function to do.

<asp:ImageButton ID="btnCheckOut" runat="server"  AlternateText="Checkout" onClick="GoCheckout"/>

Open in new window


Here is what the code for the button looks like at runtime:
 <input type="image" name="ctl00$ContentPlaceHolder1$btnCheckOut" id="ctl00_ContentPlaceHolder1_btnCheckOut" src="/images/checkout.png" alt="Checkout"  />

Open in new window


Any assistance would be appreciated.

0
Comment
Question by:Jorhal
3 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36977461
Use :

document.getElementById("btnCheckOut").click();

or :

document.getElementById("<%= btnCheckOut.ClientID %>").click();
0
 
LVL 9

Expert Comment

by:experts1
ID: 36977574
The javascript function below "GoCheckout()" will trigger an alert box when btnCheckOut
is clicked!

           <script language="javascript">
                  function GoCheckout(){
                        // this example is triggers alert box when button is clicked
                        // replace with whatever Javascript code you need to run
                        alert("The Checkout Button was clicked");
                  }
            </script>
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36977970
Very simple In page_load subroutine Add


btnCheckOut.Attributes.Add("onclick", "GoCheckout();")
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question