2013-03-27 73 views
-2

我有下面的代码复选框在页面上。当页面加载时,我需要默认选中它们。这显示查询的结果。现在,当其中一个复选框未选中时,需要提交表单并显示不同的查询结果。即使我取消选中一个框,检查总是被检查。有人可以在这里指导我吗?感谢在页面加载默认单选按钮

<form action="abc.cfm?show=yes" method="post" name="myform"> 
     <table align="center"><tr> 
     <td> 
    <input type="checkbox" checked="checked" name="chkbox" id="chkbox1"> <font size="3+"><strong> Agreement  Only</strong> </font> 
     &nbsp;&nbsp;<input type="hidden" name="chk" id="chk1"> 
     <input type="checkbox" checked="checked" name="chkbox" id="chkbox2"> <font size="3+"><strong>Active   Employees</strong> </font> 
    &nbsp;&nbsp;<input type="hidden" name="chk" id="chk2"> 
    </td> 
    <td> 
     <input type="Submit" name="submitnow" value="View now"> 
    </td> 
     </table> 
     </form> 

      <cfif isdefined("form.chk1")> 
        query 1 
       <cfelseif isdefined("form.chk2")> 
        query 2 
      </cfif> 
+0

当你说你需要保存所选的单选按钮状态时,你是什么意思?你需要服务器端还是客户端? – 2013-03-27 16:54:40

+0

在客户端... – user747291 2013-03-27 17:18:34

回答

0

你可以使用一个<input type="hidden" value=" (the value of your checkbox here) "/>存储,然后发送选中的值。

刚才你说'保存选定的单选按钮状态'是什么意思?

在您的表单发布到的页面中,您将知道哪个复选框通过检查您的发布变量进行检查。如果你的想法是再次显示与上面的代码的页面,与用户选择的复选框选中,你可以看看以下(jQuery的1.6+):

$("#chkboxId").prop('checked', true); //check the checkbox with id chkboxId. 
$("#chkboxId").prop('checked', false); //uncheck it. 
0
var states = [false, false, true]; 

function saveStates() 
{ 
    var context = $("#chk1,#chk2,#chk3"); 
    $(context).each(function (index) { 
     states[index] = $(context[index]).prop("checked"); 
    }); 
} 

我没有测试这个,也许在某处有语法错误,但你明白了。您需要使用jQuery来应用我的解决方案。