0

我在冷融合表格上有 2 个复选框,如下所示。在页面加载时,我希望同时检查并根据选中的复选框显示查询结果。我的以下代码工作正常,除了我现在取消选中复选框并点击视图的场景。作为即时设置

form.chkbox="" 

在页面加载时,即使我取消选中它们,它们仍然处于选中状态。我怎样才能让它们在页面加载时保持未选中状态。我尝试使用 JS 函数,但它似乎不起作用

     <script type="text/javascript">
  function callme(){
var box1 = document.getElementById('chkbox1').checked;
var box2 = document.getElementById('chkbox2').checked;
if (box1 && box2){
          alert("checked") ;
}else{    
box1.checked = false;
box2.checked = false;
}
}

 </script>  

    <cfset form.chkbox=""> 

    <form action="view_emp_qual.cfm?show=yes" method="post" name="Myform">
     <table align="center">
     <tr>
    <td>
  <cfif isDefined("form.chkbox") and (form.chkbox eq "" or listfind(form.chkbox, 1))>
  <input type="checkbox" checked="checked" name="chkbox" id="chkbox1" value="1">      
  <cfelse>
  <input type="checkbox" name="chkbox"  id="chkbox1" value="1">
   <input type="hidden" name="chkbox"  id="chkbox1" value="1">
  </cfif>
    <strong> Agreement Only</strong> &nbsp;&nbsp;
    <cfif isDefineD("form.chkbox") and (form.chkbox eq "" or listfind(form.chkbox, 2))>
      <input type="checkbox" checked="checked" name="chkbox" id="chkbox2" value="2">
    <cfelse>
     <input type="checkbox" name="chkbox"  id="chkbox2" value="2">
      <input type="hidden" name="chkbox"  id="chkbox2" value="2">
    </cfif>

    <strong>Active Employees</strong> &nbsp;&nbsp;
   </td>
  <td><input type="Submit" name="submitnow" value="View Selected" class="button"  onclick="return callme();">      </td>

      </tr>
      </table>
      </form> 


    <cfif not isDefined("form.chkbox")>
     Query1
     <cfelseif isDefined("form.chkbox") and ( listfind(form.chkbox, 1) eq 0 and listfind(form.chkbox, 2) eq 1)>
      Query 2
     <cfelseif isDefineD("form.chkbox") and (listfind(form.chkbox, 1) eq 1 and listfind(form.chkbox, 2) eq 0)>
    query 3
     <cfelse>
    query4
    </cfif>
4

1 回答 1

0

如果您在同一页面中提交表单,那么以下代码可能会解决您的目的。

我对你的主要代码做了一些调整。请看一看。

    <cfdump var="#form#" label="before">
    <!---flag for checking if form has submitted or not--->
    <cfif Not isDefined("form.submitnow")>
        <cfset form.chkbox = "1,2">
    </cfif>
    <cfdump var="#form#" label="after">
    <cfif isDefined("form.chkbox") > 
    <cfdump var="#listfind(form.chkbox, 1)#" ><br>
    <cfdump var="#listfind(form.chkbox, 2)#" >
    </cfif>


        <form action="" method="post" name="Myform">
            <table align="center">
                <tr>
                    <td>
                        <!---I have removed hidden fields and made a few changes in conditional checking    --->
                        <cfif isDefined("form.chkbox") and (listfind(form.chkbox, 1))> 
                            <input type="checkbox" checked="checked" name="chkbox" id="chkbox1" value="1"><span>1</span>      
                        <cfelse>
                            <input type="checkbox" name="chkbox"  id="chkbox1" value="1"><span>2</span> 
                        </cfif>

                        <strong> Agreement Only</strong> &nbsp;&nbsp;
                        <cfif isDefineD("form.chkbox") and (listfind(form.chkbox, 2))>
                            <input type="checkbox" checked="checked" name="chkbox" id="chkbox2" value="2"><span>3</span> 
                        <cfelse>
                            <input type="checkbox" name="chkbox"  id="chkbox2" value="2"><span>4</span> 
                        </cfif>
                        <strong>Active Employees</strong> &nbsp;&nbsp;
                    </td>
                    <td>
                        <input type="Submit" name="submitnow" value="View Selected" class="button">      
                    </td>

                </tr>
            </table>
          </form> 


        <cfif not isDefined("form.chkbox")>
         Query1
         <cfelseif isDefined("form.chkbox") and ( listfind(form.chkbox, 1) eq 0 and listfind(form.chkbox, 2) eq 1)>
          Query 2
         <cfelseif isDefineD("form.chkbox") and (listfind(form.chkbox, 1) eq 1 and listfind(form.chkbox, 2) eq 0)>
        query 3
     <cfelse>
    query4
    </cfif>
于 2013-04-10T17:56:06.617 回答