Get Php variable value from while loop into a javaScript -


i have ajax function connects database fetch "rows" of info. achieved using while..fine..

i want value of while loop assigned radio button.

when click each radio button, want display value assigned it. i.e.

while($row = mysqli_fetch_array($res, mysqli_assoc)) {    $mn = $row['mn'];    echo $mn . "<td onclick = \"vote()\">    <input type = \"radio\" id = \"votecan\" value = \"$mn\">    </td>     </tr>"; } echo "</table>"; 

the above query displays multiple results.

i have javascript function fired when user clicks of radio button, javascript function getting value of first row. it's not getting other rows.

please appreciated.

try this

while($row = mysqli_fetch_array($res, mysqli_assoc)) {    $mn = $row['mn'];    echo $mn . "<td onclick = \"vote(this)\">    <input type = \"radio\" id = \"votecan\" value = \"$mn\">    </td>     </tr>";   }  echo "</table>";   <script> function vote(e){  var val = $(this).val();  alert(val); } </script> 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -