SUM radio button values and checkboxes values in one calculation - javascript and html

后端 未结 2 1792
春和景丽
春和景丽 2021-01-21 20:08

I am trying to calculate the values of radio buttons and checkboxes. I have the radio buttons working as required but cannot get the script right for the checkboxes. I want the

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-21 20:10

    In Javascript if there is single texbox of a specific name then length function will be return undefined.

    Here you can do two things.

    First there is only single field of subtotal so u can assign value direct to val4 like given below

    val4 = document.form4.price4.value;
    

    Second If you want to run for loop then

      var val4 = 0;
      var form4 = document.form4.getElementsByTagName('input');
      for( i = 0; i < form4.length; i++ ){
           if(form4[i].type == 'text' && form4[i].name == 'price4'){
              if(isNaN(parseInt(form4[i].value)) == false){
                   val4 = parseInt(parseInt(val4) + parseInt(form4[i].value));
               }
           }
    
        }
    

    Edited

    In function

    
    

    i hope it will be work for you

    thanks

提交回复
热议问题