2013-03-27 35 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來應用我的解決方案。