开发者

Return Form Submit After JS Interstitial

I have a form and onSubmit, I pop-up a div with a link on it that essentially says "Are you sure you want to submit this data?" (There is other stuff in the div, but that is not relevant - using confirm() is not an option).

I then need to continue with the form submission if they click the link in the pop-up div:

<a href="" id="submitOverride">Yes, submit this data</a>

I'm stuck at how to return the form submission on click of this link.

Edit: Here's my js & html so far:

google.setOnLoadCallback(function()
{
    $('#submit').click(function(e) {
        acceptedProductCheck(e);
    });
});

function acceptedProductCheck(e)
{

    var needles = ['term1','term2','term3'];
    var haystack = $('#subject').val().toLowerCase() + ('#question').val().toLowerCase();
    haystack = haystack.split(' ');

    // check to see if #subject or #question contains 
    // a trigger term - if so, pop the div
    for (keyA in haystack) {
        for (keyB in needles) {
            if(haystack[keyA] == needles[keyB]) {
                showProductConfirmMessage(e);
            }
        }
    }

    return true;
}

function showProductConfirmMessage(e)
{
    e.preventDefault();

    $('#support').hide();
    $('#contactUs').slideUp('fast', function() {
        $('#productCheck').slideDown('fast');
    });

    $("#submitOverride").click(function(){
        $('form#contactUs').submit();
    });
}

And the HTML is pretty straightforward. It's basically my form with the hidden div that get's shown.

<form id="contactUs">
  ...
</form>开发者_如何学C

<div id="#productCheck">
   <a href="" id="submitOverride">Yes, submit this data</a>
</div>

Just a quick note for anyone else who reads this:

I was only able to get this to work by removing the submit button and replacing it with just a regular button. I'm not sure why having a submit button mattered, but when it was present, .submit() wouldn't work.


First of all use an empty hash in your link href attribute:

<a href="#" id="submitOverride">Yes, submit this data</a>

And in your link click event, return false:

$("#submitOverride").click(function(){
    $('form#contactUs').submit();
    return false;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜