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.
Here is what the code for the button looks like at runtime:
Any assistance would be appreciated.
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"/>
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" />
Any assistance would be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Very simple In page_load subroutine Add
btnCheckOut.Attributes.Add ("onclick" , "GoCheckout();")
btnCheckOut.Attributes.Add
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>