2016-04-08 6 views
0

を確認して、次の提出とJavascriptのポップアップは、私は、フォームを持っている

<form action="addaddresspage3.html" method="post" id="form" class="form"> 

<input type="submit" id="continue" value="Add Address"/> 

ユーザーがボタンをクリックするので、彼らはその後、addaddresspage3.htmlするように指示されています。フォームは完全にうまく動作します。しかし、私はいくつかの種類の確認オプション(JavaScriptかjQueryのどちらかと思います)を持つ方法があるかどうか疑問に思っていました。たとえば、ユーザーがボタンをクリックした後、「続行しますか?」などのメッセージをポップアップ表示すると、ユーザーは「はい」をクリックしてaddaddresspage3.htmlに移動します。いいえ、彼らは同じページにとどまります。私はさまざまなJSのポップアップを見ましたが、メッセージを表示するだけでOKをクリックしたときにユーザーをページに誘導するようにはできません。

+0

これは非常によく似た質問です。http://stackoverflow.com/a/6493075/6033381 –

+0

ここでは、https://jqueryui.com/dialog/#modal-confirmation – Candide

答えて

0

jqueryイベントbeforeunloadを使用して、現在のページを離れます。 は以下のようにそれを使用してください:彼らは[はい]を選択しますと、同じページに滞在している場合

$(window).bind('beforeunload', function(){ 
    return 'Are you sure you want to leave?'; 
}); 
2

確かに、あなただけのフォームを送信Javascriptをconfirm()コールを使用し、ユーザ選択を返すあなたのボタンにonclick属性を(追加することができます彼らは)何も選択した場合:

<input type="submit" ... onclick='return confirm("Are your sure you want to continue?");'/> 

をあなたは以下の見えないsee the most basic demonstration of this hereできると:

<form> 
    <input type="submit" onclick='return confirm("Are your sure you want to continue?");'/> 
</form> 
+0

Perfectに行っています。ありがとうございました – Rich

0
<form action="addaddresspage3.html" method="post" id="form" class="form" onsubmit="javascript:return getConfirm();"> 
    <input type="submit" id="continue" value="Add Address"/> 
</form> 
<script> 
function getConfirm(){ 
    if(!window.confirm('Are you sure?!')) 
     return false; 
    return true; 
} 
</script> 
関連する問題