how to send data from Javascript to PHP code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SeeMe
    New Member
    • Mar 2008
    • 18

    how to send data from Javascript to PHP code

    Code:
    <script>
    function display_check(i)
    {
    	if(i==0) {return true;}
    	else if(i!=0) {return false;}
    }
    
    function run()
    {
        if (t-1 >= 0)
        {
            t = t - 1; 
            document.getElementsByValue('text').innerHTML =display_check(t);
        }
    }
    </script>
    <body>
    <input type="button" onclick="run()" />
    <?
    $text = "<p id=\"text\"></p>"
    echo $text;
    ?>
    </body>
    This case can display the "false" and "true" on the screen. But cnt display in if else statement.
    who know other way can use in if else statement to display? Thank you.

    notice: Please enclose your posted code in [code] tags (See How to Ask a Question). So use [code] tags in future. - MODERATOR
    Last edited by ronverdonk; Mar 25 '08, 02:25 PM. Reason: code tags
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Doesn't make sense. You have your php calling one function which calls another? What "if else" statement are you talking about?

    Comment

    • SeeMe
      New Member
      • Mar 2008
      • 18

      #3
      Code:
      <script>
      function display_check(i)
      {
      if(i==0) {return true;}
      else if(i!=0) {return false;}
      }
      
      function run()
      {
      if (t-1 >= 0)
      {
      t = t - 1; 
      document.getElementsByValue('text').innerHTML =display_check(t);
      }
      }
      </script>
      <body>
      <input type="button" onclick="run()" />
      <?
      $text = "<p id=\"text\"></p>";
      /******************if else statement***********************/
      if ($text == true)
      {echo "finish";}
      else if ($text == false)
      {echo "running!";}
      /************************************************************/
      ?>
      </body>
      my if else statement show an above. thank you
      Last edited by ronverdonk; Mar 25 '08, 02:23 PM. Reason: code tags!!

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by SeeMe
        This case can display the "false" and "true" on the screen. But cnt display in if else statement.
        who know other way can use in if else statement to display? Thank you.
        Unfortunately, there are lots of mistakes and bad algorithms in your program.
        First of all you should know that JavaScript and PHP are not executed together.
        PHP runs on the server and sends HTML and JavaScript to the browser. On the browser, runs the JavaScript.
        And there is nothing called getElementByVal ue in JavaScript.
        If a condition provided in an if statement is not true, it automatically executes the else statement. You don't have to provide the opposite condition in another if statement.

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          warning: Please enclose your posted code in [code] tags (See How to Ask a Question).

          This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

          Please use [code] tags in future.

          MODERATOR

          Comment

          Working...