什么是错在这code它仍然给了MSGBOX如果用户选择或不选择复选框? [英] Whats wrong in this code it still gives the msgbox if user select or not select the checkbox?

查看:153
本文介绍了什么是错在这code它仍然给了MSGBOX如果用户选择或不选择复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它仍然给了MsgBox,如果我选择复选框BOX OR NOT ....

下面

我的code会重定向到谷歌在这两个条件:如果用户选择的复选框,然后它会重定向到www.google.com,但如果用户忘记选中该复选框,然后它显示了味精盒有一个确定按钮。当我点击确定它应该重定向到www.google.com

我想

当用户忘记检查任何复选框来展示使用了MsgBox与OK键并保持在同一页上。否则,如果用户选择任何复选框,然后重定向到www.google.com

 < HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
<头=服务器>    <标题>无标题页< /标题>
    < /头>
<身体GT;
    <表ID =form1的=服务器>
    < D​​IV>        < ASP:复选框ID =CheckBox1=服务器/>
        < ASP:复选框ID =CheckBox2=服务器/>    < / DIV>
    < ASP:按钮的ID =Button1的=服务器的OnClientClick =返回ConfirmSelection(this.form);文本=按钮/>
    < /表及GT;
    <脚本类型=文/ JavaScript的>
功能ConfirmSelection(FRM)
{
   对于(I = 0; I&下; = 1;我++){
     // chkSubjectOfInterest是你的CheckBox控件的ID     如果(frm.elements [I] .name.indexOf('chkSubjectOfInterest')!= - 1)
     {
       如果(frm.elements [I] .checked)
       {
         返回true
       }
     }
   }
   警报('您还没有选择的项目呢!)
   返回false
}
< / SCRIPT>
< /身体GT;
< / HTML>


解决方案

这一点吗?

 为(i = 0; I {

应该是这样

 为(i = 0; I< = loopnumber;我++)
{}

IT STILL GIVES A MSGBOX IF I SELECT THE CHECKBOX BOX OR NOT ....

My code below will redirect to Google in both conditions: If the user selects the checkbox, then it will redirect to www.google.com, but if a user forgets to check the checkbox then it shows the msg box with an ok button. When I click on ok it should redirect to www.google.com

I want

When a user forgets to check any of the checkboxes to show a msgbox with an ok button and stay on the same page. Otherwise if user selects any of the checkboxes then redirect to www.google.com

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <title>Untitled Page</title>
    </head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:CheckBox ID="CheckBox1" runat="server" />
        <asp:CheckBox ID="CheckBox2" runat="server" />

    </div>
    <asp:Button ID="Button1" runat="server" OnClientClick ="return ConfirmSelection(this.form);" Text="Button" />


    </form>
    <script type="text/javascript">
function ConfirmSelection(frm) 
{ 
   for (i=0; i<=1; i++) {
     //chkSubjectOfInterest is the id of your checkbox control

     if (frm.elements[i].name.indexOf('chkSubjectOfInterest') !=-1) 
     { 
       if (frm.elements[i].checked) 
       { 
         return true
       } 
     } 
   } 
   alert('You havent selected an Item yet!')
   return false
}
</script>
</body>
</html>

解决方案

this bit?

 for (i=0; i   { 

Should be something like

for (i=0; i <= loopnumber; i++)
{

}

这篇关于什么是错在这code它仍然给了MSGBOX如果用户选择或不选择复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆