2011-12-30 15 views
0

私は3つのフォームと、このようなチェックボックスがあります。私が何をしようとしています何複数のフォームでチェックボックスを検証する方法は?

<input type="checkbox" name="confirm_agreement" value=yes <?php if (isset($_POST["confirm_agreement2"])) {print "checked";}?>>I agree 

<form action="https://www.paypal.com/webscr" method="post"> 
     <input type="image" src="https://www.paypal.com/en_US/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> 
     <input type="hidden" name="cmd" value="_xclick-subscriptions"> 
     <input type="hidden" name="business" value="[email protected]"> 
     <input type="hidden" name="no_shipping" value="1"> 
     <input type="hidden" name="no_note2" value="1"> 
     ... 
     <input type="hidden" name="sra" value="1"> 
</form> 

<form action="https://www.paypal.com/webscr" method="post"> 
     <input type="image" src="https://www.paypal.com/en_US/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> 
     <input type="hidden" name="cmd" value="_xclick-subscriptions"> 
     <input type="hidden" name="business" value="[email protected]"> 
     <input type="hidden" name="no_shipping" value="2"> 
     <input type="hidden" name="no_note2" value="2"> 
     ... 
     <input type="hidden" name="sra" value="2"> 
</form> 

<form action="https://www.paypal.com/webscr" method="post"> 
     <input type="image" src="https://www.paypal.com/en_US/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> 
     <input type="hidden" name="cmd" value="_xclick-subscriptions"> 
     <input type="hidden" name="business" value="[email protected]"> 
     <input type="hidden" name="no_shipping" value="2"> 
     <input type="hidden" name="no_note2" value="2"> 
     ... 
     <input type="hidden" name="sra" value="2"> 
</form> 

は、これらの3つの形式のいずれかを提出しているチェックボックスをユーザがクリックを検証することです。

ユーザーがボックスにチェックを入れていない場合は、警告が表示されます。

私のようなもの、私はいくつかのJavaスクリプトを使用する必要があります知っている:

function checkCheckBoxes() { 
if (document.frmTest.confirm_agreement.checked == false) 
{ 
    alert ('You must agree with the User Agreement Terms!'); 
    return false; 
} 
} 

は、その後、フォームにonsubmit="return checkCheckBoxes();"を追加するが、これは動作しません。

どのようにこれを行う必要がありますか?

おかげ

+0

として、このようにそれを行うことができます。(関数(){場合を(提出!あなたがjQueryやその他のJSライブラリを使用していない理由はありますか?($ {'confirm_agreement'})あなたの人生を記念碑的に簡単にするには? – meagar

+0

私は、ありがとう – Patrioticcow

答えて

0

あなたはそれが、 `$( 'フォーム')のようなものはjQueryの切り取ら一行だ

 


function checkCheckBoxes() { 
if (document.getElementsByName('confirm_agreement')[0].checked == false) 
{ 
    alert ('You must agree with the User Agreement Terms!'); 
    return false; 
} 
} 
 
+0

ありがとう、ありがとう – Patrioticcow

関連する問題