Jump to content

NorKayak

New Members
  • Posts

    8
  • Joined

  • Last visited

Posts posted by NorKayak

  1. I have a general question. Just need to be put on the right direction.

     

    I made that little game I put on a server. Now I wish that 2 persons could play against each other online. So I made a signup/login and I can list all the users against which you would like to play. Now how could I know who is actually online and send him/her an alert when it is his/her turn to play?

     

    My first idea was to send emails every time it's a player turn to make a move; but there must be something more elegant to do in-game?

     

    I'm having a lot of fun coding that thing and any help would be great 🙂

  2. When viewing the page in your browser, does the correct name appear in the source code?

     

    Are you getting any JavaScript errors? In case you're not aware, you can right-click the page in a browser like Chrome. Then click the Inspect Element option. The errors would be displayed in the Console tab.

    Thanks I didn't think about that... I checked and the codes reads: var tempoVar = null;

    It seems then that the $_SESSION variable is not recognized in the function. Could that have something to do with declaring the variable global? So I tried this:

     
    <?php
    $theName = global $_SESSION['$Sess_Name'];
    ?>
     
    But the browser doesn't accept it...
  3.  

    It looks like json_encode() adds the quotes for you. Try changing this:

    var tempoVar = "<?php echo json_encode($theName); ?>";
     
    To this:
    var tempoVar = <?php echo json_encode($theName); ?>;

     

    Ok, I tried. Still not working. The diference is before I had the output "NULL" and now nothing...

  4. Hi;

    I'm a beginner and I'm getting a big headache figuring how to convert php variables into Javascript variables.
    I want to use the content of $theName as the value for an input tag. $_SESSION['$Sess_Name'] is loaded with the right data, I verified it. But my function InitField returns always the word NULL.
    Why is that? Where is the problem?

    Thank

     

    Here is my code:

     

    function InitField() {

        <?php
            $theName = $_SESSION['$Sess_Name'];
        ?>
        var tempoVar = "<?php echo json_encode($theName); ?>";
        var myInput = document.getElementById('theSurname');
        myInput.value = tempoVar;
    }
     
     
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.