2012-03-08 8 views
0

データリストを含むフォームがあります。最上位のチェックボックスをクリックすると、それぞれのチェックボックスが追加されました。しかし、もし私が1行のデータしか持っておらず、一番上のチェックボックスをクリックすれば、仕事はできません。以下にスクリプトを示します。Field.lengthは1つのチェックボックスでは機能しません

////checking all checkbox on page 
function checkAll(field) 
{ 
    // alert(field.length); 
    for (i = 0; i < field.length; i++){ 
     field[i].checked = true ; 
    } 
} 

////unchecking all checkbox on page 
function uncheckAll(field) 
{ 
    for (i = 0; i < field.length; i++){ 
     field[i].checked = false; 
    } 
} 
function selectCHK(e){ 
    if(e.checked==true){ 
     //alert("Yeah"); 
     checkAll(document.paginate_list.list);         
    }else{ 
     uncheckAll(document.paginate_list.list); 

    }        
} 

function ApplyToSelected(){ 
var SelectedVal=""; 
var withSelected=document.getElementById("withSelected"); 
// 
if(withSelected.value==1){ 

    //if(document.getElementById("list")){ 

    // SelectedVal=document.getElementById("list").value; 

    //} 
for(i=0; i<document.paginate_list.list.length;i++){ 
     if (document.paginate_list.list[i].checked) { 
      //alert(i); 
      SelectedVal +=document.paginate_list.list[i].value+","; 

     } 
    } 

     if(SelectedVal==""){ 
      return false; 
     } 

    if(confirm("Are you Sure you want to Delete the Selected Row?")){ 
     $.ajax({ 
      url: "../__lib__/pagingLib.php?tableDeleteID="+SelectedVal, 
      context: document.body, 
      success: function(response,status,xhr){ 
      if(response==1){ 
       alert("Deleted Successfully"); 
       window.location.reload(); 
      }else{ 
       alert(response); 
       alert("An Error Occurred while Deleting, Please Try Again!"); 
      } 
      // alert(response); 
      } 
     }); 
    } 

} 
} 

HTMLデータ

<form name="paginate_list" style="display:inline;" action="" method="post"> 
<table class="PagingBody"> 
<tr> 
<th><input type=checkbox onclick=selectCHK(this) ></th> 
<th>Category Title</th><th>Actions</th> 
</tr> 
<tr class="even"> 
<td><input name=list[] type=checkbox id=list value=10></td> 
<td>Web Design</td> 
<td><a href=?page=cat&edit=10>Edit</a> | <a href=#10>Delete</a></td> 
<tr/> 
</table> 

<table> 
<tr> 
<td> 
<select name="withSelected" id="withSelected"> 
<option value="0">With Selected</option> 
<option value="1">Delete</option> 
</select> 

<input type="button" name="applyToSelected" id="applyToSelected" value="Apply to Selected" onclick="ApplyToSelected()" /> 
</td> 
<tr/> 
</table> 
</form> 

paginate_list.list私のフォームとリスト名の名前を表します。

+0

フォームのHTMLとは何ですか? http://jsfiddle.netに載せてリンクを提供できますか? – nicholaides

+0

ok nicho ...実際には私はまだlocalhostで作業しています... buh私はここでもhtmlフォームのデータを投稿します..thanks man – shola

+0

申し訳ありません、私はjsfiddleの例へのリンクを提供することを意味しました。 – nicholaides

答えて

0

このバイオリンは何が起こっているかを説明します

FIDDLE HERE

このブラウザはあなたが関数に送るリストに複数の要素を持っているのNodeListを生成しているためである起こっている理由checkAll(); それ以外の場合は、通常の入力要素を取得します。

私はinstanceofのチェックを付けて、それがどのタイプのオブジェクトであるかを確認しました。 NodeList check in IE

幸運:IEでこれを確認するには

は、SOに、ここでこのスレッドに従ってください!

関連する問題