Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

My problem is if I select more than one radio button sometimes both value gets stored. Why?

$
0
0

function ajax_value_save(id) {
  if (document.getElementById('a').checked) {
    var rate_value = document.getElementById('a').value;
  } else if (document.getElementById('b').checked) {
    var rate_value = document.getElementById('b').value;
  } else if (document.getElementById('c').checked) {
    var rate_value = document.getElementById('c').value;
  } else if (document.getElementById('d').checked) {
    var rate_value = document.getElementById('d').value;
  }
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      var result1 = document.getElementById('val1');
      result1.innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.open('GET', 'answersave.php?valsave=' + rate_value + '&qid=' + id, true);
  xmlhttp.send();
}

if(!empty($_REQUEST['valsave'])){
$valsave = $_REQUEST['valsave'];
$id = $_REQUEST['qid'];
}
array_push($_SESSION['answers'], $valsave);
array_push($_SESSION['quid'], $id);

If I select the correct answer it's okay, but if sometimes I try to select one after the other radio buttons more than one answer gets stored. The thing is if there are four multiple-choice and I choose the right one it's fine but if I continue selecting more than one and submit the answer more than one answer gets stored.


Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>