Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to display the sum of values from two groups of input - ajax
    primarykey
    data
    text
    <p>I wanted to sum up the values from group name='s' and group name='v' when radio button clicked, they call the function pieces(str, str2)</p> <p>the problem is, it seems like the execution of ajax here comes at a time. cant get the value of 1st group when 2nd group is activated, vise versa</p> <p>these are the inputs</p> <pre><code> &lt;input type='radio' id='1' name='s' onclick='pieces(this.value);' value='6'&gt;6 &lt;input type='radio' id='2' name='s' onclick='pieces(this.value);' value='12'&gt;12 &lt;input type='radio' id='3' name='s' onclick='pieces(this.value);' value='24'&gt;24 &lt;input type='radio' id='11' name='v' onclick='pieces(this.value);' value='50'&gt;Yes &lt;input type='radio' id='12' name='v' onclick='pieces(this.value);' value='0'&gt;No &lt;div id='txtHint'&gt;Sum will display here&lt;/div&gt; </code></pre> <p>here's my script</p> <pre><code> $(document).ready(function(){ $('#btn').click(function(){ var str1=$('input:radio[name=s]').val(); var str2=$('input:radio[name=v]').val(); pieces(str1,str2); }); }); function pieces(str1, str2) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById(txtHint).innerHTML=xmlhttp.responseText; } } xmlhttp.open('GET','url.php?var1='+str1+'&amp;var2='+str2,true); xmlhttp.send(); } </code></pre> <p>heres the link page at ajax code</p> <pre><code> &lt;?php $s = $_GET['s']; $v = $_GET['v']; if($s == 6 &amp;&amp; $v == 50) echo"value"; else if($s == 6 &amp;&amp; $v == 0) echo"value"; else if($s == 12 $v == 50) echo"value"; else if($s == 12 $v == 0) echo"value"; else if($s == 24 $v == 50) echo"value"; else if($s == 24 $v == 50) echo"value"; ?&gt; </code></pre> <p>please help. newbie here</p>
    singulars
    1. This table or related slice is empty.
    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.
    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