Jump to content
Killersites Forums

After clicking on submit button, warning box appears... I don't want it


Recommended Posts

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;

});

Link to post
Share on other sites

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 by khanahk
Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...