Can I ask if it is possible to print result of a "checked" radio button without a submit button in php with ajax?
In my code below, I wanted to print "Thank you" when the "Yes" radio button is being clicked; and "Are you sure?" when the "No" button is being clicked without refreshing the page.
<script>
function getEmail(int){
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("emailQ").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "index.php?q="+int, true);
xmlhttp.send();
}
</script>
<div id = "emailQ">
<li class="nav-header">Please confirm your facebook email:</li>
<li><?php echo $_SESSION['EMAIL']; ?></li>
<form action="" method="post">
<input type="radio" name="email" onclick="javascript: submit.getEmail()" value="Thank You"> Yes
<input type="radio" name="email" onclick="javascript: submit.getEmail()" value="Are you sure?"> No
</form>
<?php
if(isset($_POST['email'])){
echo " ".$_POST['email'];
}
?>
</div>