Display lable character by character using javascript

Posted by Muhammad Sajid on Stack Overflow See other posts from Stack Overflow or by Muhammad Sajid
Published on 2010-05-23T11:23:18Z Indexed on 2010/05/23 11:30 UTC
Read the original article Hit count: 323

Filed under:
|

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 = 'none';

            }
        }
    }
</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>&nbsp;</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>

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript