Javascript 单选按钮值计算。第四种选择不会求和

Javascript 单选按钮值计算。第四种选择不会求和,javascript,sum,Javascript,Sum,伙计们 我有一个计算单选按钮中定义的值的脚本。出于某种原因,我无法理解为什么脚本会跳过一个组。似乎被跳过的组(被跳过的意思是所选值不会被添加)与每个组中使用的单选按钮数量相关 这件事我一直很紧张 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> function setRadios() { function sumRadios(){ var to

伙计们

我有一个计算单选按钮中定义的值的脚本。出于某种原因,我无法理解为什么脚本会跳过一个组。似乎被跳过的组(被跳过的意思是所选值不会被添加)与每个组中使用的单选按钮数量相关

这件事我一直很紧张

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function setRadios()
{
function sumRadios(){
var total = 0, i = 0, oForm = this.form, e, len, j, c;
while(e=oForm.elements[i++]){

//This is probably the issue - Maybe it would be easier to manually define the names verses detecting them incrementally.
    if(e.name.match(/^m4j-\d/)){ 
        c=document.getElementsByName(e.name);
        for(j=0;j<c.length;j++){
            c[j].checked?total+=Number(c[j].value):null;
        i++;
        }

    }
}
// Defines the field that totals the selections
oForm.elements['m4j-65'].value = total.toFixed(0);
}
// Must define form name "m4jFrom"
var i = 0, input, inputs = document.getElementById('m4jForm').getElementsByTagName('input');
while (input = inputs.item(i++))

// This executes the sum onclick
if (input.name.match(/^m4j-\d/)) 
input.onclick = sumRadios;
}
onload = setRadios;

</script>
<style type="text/css"></style>
</head>

<body>
<form id="m4jForm" name="m4jForm" method="post" enctype="multipart/form-data" action="">
  <table  border="0" align="left" cellpadding="11" cellspacing="11" class="m4j_form_table">
    <tbody>
      <tr id="m4je-57"  >
        <td colspan="2" align="left" valign="top"><table border="1" style="width: 100%;" >
            <tbody>
              <tr>
                <td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-57-0" name="m4j-57" value="1" >
                  </input>                  1 </td>
              </tr>
              <tr>
                <td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-57-1" name="m4j-57" value="2" >
                  </input>
                  2 </td>
              </tr>
            </tbody>
          </table></td>
      </tr>

      <tr id="m4je-61"  >
        <td colspan="2" align="left" valign="top"><table border="1" style="width: 100%;" >
            <tbody>
              <tr>
                <td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-61-0" name="m4j-62" value="1" >
                  </input>
                  1 </td>
              </tr>
              <tr>
                <td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-61-1" name="m4j-62" value="2" >
                  </input>
                  2  </td>
              </tr>
            </tbody>
          </table></td>
      </tr>
      <tr id="m4je-62"  >
        <td colspan="2" align="left" valign="top"><table border="3" style="width: 100%;" >
            <tbody>
              <tr>
                <td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-62-0" name="m4j-63" value="1" >
                  </input>
                  1 No Calculation </td>
              </tr>
              <tr>
                <td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-62-1" name="m4j-63" value="2" >
                  </input>
                  2 if you remove this table the non calculation will move to the radios below</td>
              </tr>
            </tbody>
          </table></td>
      </tr>
      <tr id="m4je-63"  >
        <td colspan="2" align="left" valign="top"><table border="1" style="width: 100%;" >
            <tbody>
              <tr>
                <td align="left" valign="top"><div class="m4jSelectItem m4jSelectItemVertical">
                    <input class="m4jRadio" type="radio" id="m4j-63-0" name="m4j-64" value="1" >
                    </input>
                    1  </div></td>
              </tr>
              <tr>
                <td align="left" valign="top"><div class="m4jSelectItem m4jSelectItemVertical">
                    <input class="m4jRadio" type="radio" id="m4j-63-1" name="m4j-64" value="2" >
                    </input>
                    2  </div></td>
              </tr>
            </tbody>
          </table>
          </div>
          </div></td>
      </tr>
      <tr id="m4je-65"  >
        <td width="300" align="left" valign="top" >Total</td>
        <td width="0px;" align="left" valign="top" >

        <input class="m4jInputField" style="width: 100%;" id="m4j-65" name="m4j-65" type="text" size="18" maxlength="60" value= "" alt="" ></input><br>

          <input type="submit" name="submit" value="send" class ="m4j_submit" >
  </input>
  <input id="m4jResetButton" class ="m4j_reset" type="reset" name="reset" value="reset">
  </input>
          </td>
      </tr>
    </tbody>
  </table>

</form>
</body>
</html>

函数集无线电()
{
函数sum无线电(){
var total=0,i=0,oForm=this.form,e,len,j,c;
while(e=of形式元素[i++]{
//这可能就是问题所在——也许手动定义名称和增量检测名称会更容易。
如果(e.name.match(/^m4j-\d/){
c=document.getElementsByName(e.name);

对于(j=0;j我找到了解决方案。我欠董事会的信息。我希望有人能从中受益。:)


函数集无线电()
{
var inputs=document.getElementById('m4jForm').getElementsByClassName('m4jRadio');
函数sum无线电(){
var总计=0,
oForm=this.form;
对于(变量x=0;x
jsFiddle用于尝试代码?
<script type="text/javascript">
function setRadios()
{

  var inputs = document.getElementById('m4jForm').getElementsByClassName('m4jRadio');
  function sumRadios(){
    var total = 0, 
        oForm = this.form;

    for(var x = 0; x < inputs.length; x++){
      if (inputs[x].checked) total += parseInt(inputs[x].value);
    }

    // Defines the field that totals the selections
    oForm.elements['m4j-65'].value = total.toFixed(0);

  }

  for(var y = 0; y < inputs.length; y++){
    inputs[y].onclick = sumRadios;
  }

}
onload = setRadios;

</script>