I have the following code, that works:
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
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 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
<body>
<?php include 'db_connector.php';
$result = mysqli_query($con,"SELECT * FROM scope");
while($row = mysqli_fetch_array($result)) {
$row['name'];
echo "<div class='toggle-btn-grp cssonly'>
<div><input type='radio' name='os' value=".$row['name']." id='myRadio' onchange='showUser(this.value)'> <label class='toggle-btn'>".$row['name']."</label></div>
</div>";
}
?>
<p>Click the "Try it" button to display the value of the radio button.</p>
<button onclick="myFunction()">Try it</button>
<div id="txtHint"></div>
</body>
Now I want to repeat the same process, using another radio button but this time I want the value of the new radio button to be what ever the user selects from <div id="txtHint"></div>
.
Is this possible at all??
Here is my backend getuser.php
file:
<?php
$q = strval($_GET['q']);
echo "<center><b>Scope ".$q."</b></center><br><br>";
include 'db_connector.php';
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM os WHERE scope = '".$q."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo "<a href=''>ID: ".$row['id']."</a><br>";
echo "<a href=''>Name: ".$row['name']."</a><br><br>";
}
mysqli_close($con);
?>
Any advice is greatly appreciated. Thanks in advance.