Javascript "if and else" statements

Javascript "if and else" statements

本文关键字:quot statements else if Javascript and      更新时间:2023-09-26

我有一个Terms of Service页面,我想强制用户在单击接受按钮之前检查Checkbox。否则,它应该显示一个弹出消息,说

在继续

之前请先阅读使用条款

,如果它被选中并点击接受按钮,他们将被重定向到官方网站。

有人能帮我吗?

try this:

<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>

检查submit handler中的condition

if (formname.checkboxname.checked == true)
   {
      //showalert
      return false;
   }else{
     //open your page
  }