Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In Javascript if <code>there is single texbox of a specific name then length function will be return undefined</code>.</p> <p>Here you can do two things.</p> <p>First <code>there is only single field of subtotal so u can assign value direct to val4 like given below</code></p> <pre><code>val4 = document.form4.price4.value; </code></pre> <p>Second <code>If you want to run for loop then</code></p> <pre><code> var val4 = 0; var form4 = document.form4.getElementsByTagName('input'); for( i = 0; i &lt; form4.length; i++ ){ if(form4[i].type == 'text' &amp;&amp; form4[i].name == 'price4'){ if(isNaN(parseInt(form4[i].value)) == false){ val4 = parseInt(parseInt(val4) + parseInt(form4[i].value)); } } } </code></pre> <p>Edited</p> <p>In function </p> <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt; var total = document.getElementById("price4") function clickCh(caller){ if(caller.checked){ add(caller) } else { subtract(caller) } finalResult(); } function add(caller){ total.value = total.value*1 + caller.value*1} function subtract(caller){ total.value = total.value*1 - caller.value*1} function finalResult(){ var val1 = 0; for( i = 0; i &lt; document.form1.price.length; i++ ){ if( document.form1.price[i].checked == true ){ val1 = document.form1.price[i].value; } } var val2 = 0; for( i = 0; i &lt; document.form2.price2.length; i++ ){ if( document.form2.price2[i].checked == true ){ val2 = document.form2.price2[i].value; } } var val3 = 0; for( i = 0; i &lt; document.form3.price3.length; i++ ){ if( document.form3.price3[i].checked == true ){ val3 = document.form3.price3[i].value; } } var val4 = 0; var form4 = document.form4.getElementsByTagName('input'); for( i = 0; i &lt; form4.length; i++ ){ if(form4[i].type == 'text' &amp;&amp; form4[i].name == 'price4'){ if(isNaN(parseInt(form4[i].value)) == false){ val4 = parseInt(parseInt(val4) + parseInt(form4[i].value)); } } } var sum=parseInt(val1) + parseInt(val2) + parseInt(val3) + parseInt(val4); document.getElementById('valueTotal').value=sum; } &lt;/script&gt; </code></pre> <p>i hope it will be work for you</p> <p>thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload