日期:2014-05-16  浏览次数:20337 次

关于多选框和单选框取值的问题
各位好:

我遇到一个问题请各位帮忙看看:

例:

<table   cellspacing= '1 '   cellpadding= '0 '   width= '95% '>
  <tr> <td   align= 'center '>
  <input   type= 'checkbox '   name= 'C1 '   value= 'A '   >
  <input   type= 'checkbox '   name= 'C1 '   value= 'B '   >
  <input   type= 'checkbox '   name= 'C1 '   value= 'C '   >
  <input   type= 'checkbox '   name= 'C1 '   value= 'D '   >
  <input   type= 'radio '   name= 'C2 '   value   = '0 '>
  <input   type= 'radio '   name= 'C2 '   value   = '1 '>
  <input   type= 'radio '   name= 'C2 '   value   = '2 '>
  <input   name= 'C3 '   type= 'button '   value= '查看选择值 '   onclick= 'review() '>
  </td> </tr> </table>

<script   language= "javascript ">

Function   review()  
  {
  var   str   =   " ";      
  var   chkbox   =   document.getElementsByName( "C1 ");    
  for(i=0;i <chkbox.length;i++)    
    {    
      if(chkbox[i].checked)==   true)   {   str+   =str   +   chkbox[i].value   }
    }


  var   radbox   =   document.getElementsByName( "C2 ");    
  for(i=0;i <radbox.length;i++)    
    {    
      if(radbox[i].checked)==   true)   {   str+   =str   +   radbox[i].value   }
    }

    document.from1.action= "userview.asp?vid= "   +   str;
    document.from1.submit();
  }                          
</script>

我想得到多选和单选的组合值用来传递,为什么总是有错误?不能正常得到选择值



------解决方案--------------------
function review(){ //function 要小写
//alert( ' ')
var str = " ";
var chkbox = document.getElementsByName( "C1 ");
for(var i=0;i <chkbox.length;i++)
{
if(chkbox[i].checked== true) { str =str + chkbox[i].value } // 多个)
}


var radbox = document.getElementsByName( "C2 ");
for(var i=0;i <radbox.length;i++)
{
if(radbox[i].checked== true) { str =str + radbox[i].value } // 多个)
}
alert(str)
//document.from1.action= "userview.asp?vid= " + str;
//document.from1.submit();
}