Display label character by character using javascript
- by Muhammad Sajid
Hi,
I am creating Hang a Man using PHP, MySQL & Javascript. Every thing is going perfect, I get a word randomly from DB show it as a label apply it a class where display = none. Now when I click on a Character that character become disable fine which i actually want but the label-character does not show.
My code is:
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<?php
include( 'config.php' );
$question = questions(); // Get question.
$alpha = alphabats(); // Get alphabets.
?>
<script language="javascript">
function clickMe( name ){
var question = '<?php echo $question; ?>';
var questionLen = <?php echo strlen($question); ?>;
for ( var i = 0; i < questionLen; i++ ){
if ( question[i] == name ){
var link = document.getElementById( name );
link.style.display = 'none';
var label = document.getElementById( 'questionLabel' + i );
label.style.display = 'block';
}
}
}
</script>
<div>
<table align="center" style="border:solid 1px">
<tr>
<?php
for ( $i = 0; $i < 26; $i++ ) {
echo "<td><a href='#' id=$alpha[$i] name=$alpha[$i] onclick=clickMe('$alpha[$i]');>". $alpha[$i] ."</a> </td>";
}
?>
</tr>
</table>
<br/>
<table align="center" style="border:solid 1px">
<tr>
<?php
for ( $i = 0; $i < strlen($question); $i++ ) {
echo "<td class='question'><label id=questionLabel$i >". $question[$i] ."</label></td>";
}
?>
</tr>
</table>
</div>