I am having a problem on replacing the character in array by character receive from another page through Ajax.
href="show.php?q=1";
when user clicks this link it goes to:
show.php
<?php
session_start();
$q = $_GET['q'];
$query = mysql_query("SELECT mname FROM BClassroom WHERE slno='".$q."'");
while($row = mysql_fetch_array($query)){
$n = $name = strtoupper($row['mname']);
}
$_SESSION['name'] = $name;
for($i = 0; $i < strlen($name); $i++){
switch($name[$i]){
case 'A':
$name[$i] = "A";
// echo 'A'." ";
break;
case 'E':
$name[$i] = "E";
// echo 'E'." ";
break;
case 'I':
$name[$i] = "I";
// echo 'I'." ";
break;
case 'O':
$name[$i] = "O";
// echo 'O'." ";
break;
case 'U':
$name[$i] = "U";
// echo 'U'." ";
break;
case ' ':
$name[$i] = "/";
// echo "/"." ";
break;
default:
$name[$i] = "_";
// echo "_"." ";
break;
}
}
echo "<p id='datatbl'>$name</p>";
?>
<fieldset>
<legend>START THE GUESS</legend>
<div>
<?php
$consonant = "BCDFGHJKLMNPQRSTVWXYZ";
$len = strlen($consonant);
for($j=0;$j<$len;$j++){ ?>
<button name='CharCheck' id="sahil" onclick=checkBollyChar(this.value) value='<?php echo $consonant[$j] ?>'><?php echo $consonant[$j] ?></button>
<?php }
?>
<p><span id="datatbl"></span></p>
</div>
<button onclick="showResult(this.value)" value="<?php echo $n; ?>">Show Result</button>
</fieldset>
<script>
function checkBollyChar(str){
if(str==""){
document.getElementById("datatbl").innerHTML="";
return;
}else{
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("datatbl").innerHTML= xmlhttp.responseText;
}
}
xmlhttp.open("GET","handler.php?q="+str,true);
xmlhttp.send();
}
buttonHide();
}
</script>
<script>
function showResult(str){
if(str==""){
document.getElementById("datatbl").innerHTML="";
return;
}else{
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("datatbl").innerHTML= xmlhttp.responseText;
}
}
xmlhttp.open("GET","Result.php?q="+str,true);
xmlhttp.send();
}
}
</script>
when user clicks on button name="charCheck"
, it should replace the "_"
with the character if it matches with actual character in the word.
for "JURASSIC"
, it shows "_ U _ A _ _ I _ _"
only vowels, so when user clicks button "J"
then "_"
in first place should be replace by "J"
.
thanks.