Forum Moderators: open

Message Too Old, No Replies

Stop Form Submission with JS

         

andrewsmd

11:19 pm on Jan 3, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am working with a dotnetnuke module to which I don't have the source code so the only thing I can edit is the front end. Not exactly ideal, but the real world never is. Anyways, I have a button like so

<asp:ImageButton ID="btnMakePayment" runat="server" OnClientClick="michaelsFunc()" ImageUrl="checkout_btn.png" OnClick="btnMakePayment_Click"/>

I can do the validation I want in michaelsFunc() however, I need to stop the OnClick event from happening if certain things are true within my JS code. Is this possible? I tried returning false, but the form still submits. Here is the JS I was using.

function michaelsFunc() { var text = document.getElementById("shippingAmountMichael").innerHTML; if (text == "TBD") { return false; } else { return true; } }//michaelsFunc
function michaelsFunc() {

var text = document.getElementById("shippingAmountMichael").innerHTML;



if (text == "TBD") {

return false;



}

else {

return true;

}

}//michaelsFunc

Fotiman

2:46 pm on Jan 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try this:

OnClientClick="return michaelsFunc();"

andrewsmd

2:57 pm on Jan 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yup, it was just too late in the day yesterday I guess. Thanks for the help.