Polar Bear Posted December 19, 2005 Posted December 19, 2005 Hi, I have a button where I want to do some javascript validation before is runs its OnClick server code. My problem is that even though the javascript function returns false the btnAdd_Click code still gets executed. Javascript function confirmAdd() { var cmbOrder=document.getElementById("cmbOrder"); var txtInvoiceNumber=document.getElementById("txtInvoiceNumber"); if (cmbOrder.value.length > 0 && txtInvoiceNumber.value.length == 0) { exit = confirm("Are you sure that this order has not been invoiced? (OK=Yes Cancel=NO)") if (exit == true) { return true; //add order } else { return false; //dont add order } } else { return true; //add order } } HTML code <asp:Button ID="btnAdd" runat="server" Width="100" Text="Add Order" CausesValidation="True" OnClick="btnAdd_Click" TabIndex="20" /> Page Load btnAdd.Attributes.Add("onclick","javascript:confirmAdd();") Quote
HJB417 Posted December 19, 2005 Posted December 19, 2005 what if you do btnAdd.Attributes.Add("onclick","return confirmAdd()") or just btnAdd.Attributes.Add("onclick","confirmAdd()") Quote
Polar Bear Posted December 21, 2005 Author Posted December 21, 2005 btnAdd.Attributes.Add("onclick","return confirmAdd();") worked! But you need the semicolor at the end. Thanks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.