Adou Pro
Adou Pro

Reputation: 51

div don't show up. Why?

I create a javascript + a php page. The script on the php page send data to my sql database, but don't show the result into on my home page.

Here the code

function getVote(question_ID) {
  var option_ID = document.querySelector("input[id='option']:checked").value;
  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 (option_ID.readyState == 4 && option_ID.status == 200) {
      document.getElementById(poll).innerHTML = option_ID.responseText;

    }
  }
  xmlhttp.open("GET", "./core/vote.php?user_ID=" + user_ID + "&question_ID=" + question_ID + "&option_ID=" + option_ID, true);
  xmlhttp.send();

}
<div id="poll">
</div>

More code

<div id="poll">
    	<form method="post" onsubmit='getVote(question_ID);' >
        <p><?php echo $question ['question_content']; ?></p>

        <p>

	<?php
	$poll_option_selection = "SELECT option_ID, option_content FROM poll_options WHERE question_ID='$question_ID'" ;
	$poll_option_result = mysqli_query ($connect,$poll_option_selection) ;
	foreach ($poll_option_result as $poll_option) { 
	$option_ID = $poll_option ['option_ID'] ;
	$option_content = $poll_option ['option_content'] ;
	?>
	<script type="text/javascript">
	var option_ID = <?php echo json_encode($option_ID) ; ?> ;
	</script>
	<input type="radio" id="option" value ='<?php echo $option_ID ?>'  required /> 
	<?php echo $option_content ?>
	</br>
	<?php
	}
	?>
	<input type="submit">
	</form>
	</div>

Thank you for your help

Upvotes: 0

Views: 86

Answers (1)

cjs1978
cjs1978

Reputation: 529

It should be:

document.getElementById("poll").innerHTML=option_ID.responseText;

document.getElementById takes the argument (id of element) as a string.

Upvotes: 2

Related Questions