2013-03-09 206 views
-3

我有一個Terms of Service頁面,我想強制用戶在點擊接受按鈕之前檢查Checkbox。否則,它應該顯示彈出消息說Javascript「if and else」語句

請繼續

之前閱讀服務條款,如果它檢查並接受按鈕,他們將重定向到官方網站。

任何人都可以幫助我嗎?

+7

你做了什麼?對我們來說什麼? – thecodeparadox 2013-03-09 20:19:59

+2

我們需要看看你到目前爲止 – 2013-03-09 20:20:53

+0

你不需要JavaScript(除非你關心舊版瀏覽器)'' – 2013-03-09 20:23:04

回答

2

試試這個:

<SCRIPT> 

//Accept terms & conditions script (by InsightEye www.insighteye.com) 
//Visit JavaScript Kit (http://javascriptkit.com) for this script & more. 

function checkCheckBox(f) { 
    if (f.agree.checked == false) { 
    alert('Please check the box to continue.'); 
    return false; 
    } else { 
    return true; 
    } 
} 
</SCRIPT> 

<form action="/yourscript.cgi-or-your-page.html" method="GET" 
onsubmit="return checkCheckBox(this)"> 

    <!--Enter your form contents here--> 
    <b>By submitting, I agree that all info entered was done 
    accurately & truthfully.</b><br> 
    I accept: <input type="checkbox" value="0" name="agree"> 
    <input type="submit" value="Submit form"> 
    <input type="button" value="Exit" onclick="document.location.href='/index.html';"> 
</form> 

或本:

<form name="frm"> 
    <input type="checkbox" name="chk" onClick="apply()">If you click this the specified 
    url will open. 
    <div align=center>&copy<a href="http://www.mine.com" style="color:#3D366F;text-decoration:none;cursor:pointer;font-size=13px">hscripts.com</a></div> 
</form> 
<script type="text/javascript"> 
    function apply() { 
    if(document.frm.chk.checked==true) { 
    window.open("http://www.mine.com/license/license.html"); 
    } 
    } 
</script> 
+0

這正是我一直在尋找的感謝! – user2152375 2013-03-09 20:27:54

+0

這些都不是特別「安全」。在第一種情況下,如果javascript被禁用,表單將提交,因此必須在服務器上進行檢查以確定複選框是否已被選中。在第二種情況下,用戶可以簡單地複製href以進入頁面。在這兩種情況下,一旦用戶到達鏈接,什麼是阻止他們未來直接訪問URL? – RobG 2013-03-09 20:39:08

+1

如果你有hav solution.plz提供。 – Amrendra 2013-03-09 20:42:21

0

入住這conditionsubmit handler

if (formname.checkboxname.checked == true) 
    { 
     //showalert 

     return false; 
    }else{ 

    //open your page 
    } 
+0

這樣比較容易理解,謝謝 – user2152375 2013-03-09 21:29:03

+0

乾杯:)如果您覺得有用,請標記爲答案。 – 2013-03-10 03:57:06