Link to home
Start Free TrialLog in
Avatar of Jorhal
Jorhal

asked on

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

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.

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of experts1
experts1

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>
Very simple In page_load subroutine Add


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