javanut Posted September 3, 2012 Report Posted September 3, 2012 I was able to get this script working, but now when form submit button is clicked the warning box appears. I only want the warning box if visitor trys to leave, etc. And I don't want the warning box when they click on submit. Anyone know how to make this so? var submitted = false; window.onbeforeunload = function() { window.onbeforeunload = null; location.assign('http://site.com); return "Stay here bla bla"; }; $("#formID").submit(function () { submitted = true; }); <form id="formID" method="post" action="http://site.com"> <input type="hidden" name="first_name" value="" /> <input type="hidden" name="last_name" value="" /> <input type="hidden" name="phone" value="" /> <input class="input_txt" type="text" id="email" name="email" value="Enter your best email..." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> <input type="submit" class="btn_get_access" value="Get Instant Access »"> </form> ***Apparently, the following code is not working. For one thing I get $ is undefined. Any help would be great. $("#formID").submit(function () { submitted = true; }); Quote
khanahk Posted September 3, 2012 Report Posted September 3, 2012 (edited) First -- You need to enclose all JavaScript and jQuery in <script> tags; and you also need to include the jQuery library in your page if you intend to use it (looks like that's the case). The fact that $ is undefined indicates your code does not have jQuery properly put in. If you've already done that, try if ($('#formID').click()) { return true; } within and at the beginning your onbeforeunload function. Edited September 3, 2012 by khanahk 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.
Note: Your post will require moderator approval before it will be visible.