2013-01-03 88 views
0

點擊按鈕「刪除」,如果選擇了沒有單選按鈕如何顯示一個警告後。我的html表格顯示警報()如果沒有單選按鈕被選中

<form name="Action" method="post" action="RequestAction"> 
        <table width="800px" cellpadding="5" style="color:black; border-top:1px solid #ccc;" border="0"> 
        </table> 
        <div id="container"> 
        <div id="demo_jui"> 
        <table id="requestList" class="display" cellpadding="0" cellspacing="0" border="0" style="font-size:12px;" > 
        <thead id="headed"> 
         <tr> 
          <th align="center" title="Employee">Employee</th> 
          <th align="center" title="Number of Days">Number of Days</th> 
          <th align="center" title="Start Date">Start Date</th> 
          <th align="center" title="End Date">End Date</th> 
          <th align="center" title="Leave Type">Leave Type</th> 
          <th align="center" title="Remark">Remark</th> 
          <th align="center">Approve</th> 
          <th align="center">Reject</th> 
         </tr> 
        </thead> 
        <tbody></tbody> 
        </table> 
        </div> 
        </div> 
         <table>     
         <tr> 
          <td style="padding-left:0px;" colspan="3"> 
           <a href="#"><img src="images/Submit.png" style="border:none;" onClick="javascript:Go()" 
           onmouseover="this.src='images/Submit_Hover.png'" onmouseout="this.src='images/Submit.png'"/></a> 
           &nbsp;&nbsp;&nbsp; 
           <a href="#"><img src="images/Reset.png" style="border:none;" onClick="javascript:clearForm()" 
           onmouseover="this.src='images/Reset_Hover.png'" onmouseout="this.src='images/Reset.png'"/></a> 
          </td> 
         </tr> 
        </table> 
       </form> 

單選按鈕值將在表格中檢索。當我測試了一下,如果沒有點擊任何選擇單選按鈕提交按鈕,我會得到錯誤

在功能圍棋(),是這樣的驗證單選按鈕是否正確?謝謝

function Go() { 
       if($('form[name=Action] input[name=statusList]:checked').length == 0) 
       { 
        $('form[name=Action]').submit(); 
       } 
       else 
       { 
        alert("Please select at least one to delete"); 
       } 
      } 
+0

你的HTML不會出現任何複選框或輸入的。此外,你的JavaScript似乎是倒退的,因爲你的條件只在沒有檢查輸入時才提交。此外,Java和異常堆棧跟蹤與問題無關。 –

回答

1

使用下面的代碼片段

var IsChecked = $('take id or classname of radiogroup').is(':checked'); 

if(!IsChecked) 
{ 
alert("select some thing"); 
} 
+0

i相 ' VAR =器isChecked $( '形式[名稱=動作]輸入[名稱= statusList]')測試它是( ':檢查'); \t \t \t功能。Go(){ \t \t \t如果(器isChecked!) \t \t \t { \t \t \t \t警報( 「請至少選擇一個要刪除」); \t \t \t \t \t \t \t} \t \t \t別的 \t \t \t { \t \t \t \t $( '形式[名稱=動作]')提交(); \t \t \t} \t \t \t} ' 但是,它保持提示警報只要選擇了單選按鈕或不 – user1944535

+0

請調試它的螢火,讓我知道了什麼是ü越來越在向器isChecked以及如何價值其餘代碼的行爲我的意思是進入如果塊和所有........我想你錯過了某些東西在獲取特定元素什麼是你的id或類名稱 – mandava

相關問題