469,361 Members | 2,396 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,361 developers. It's quick & easy.

how to send data from Javascript to PHP code

18
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function display_check(i)
  3. {
  4.     if(i==0) {return true;}
  5.     else if(i!=0) {return false;}
  6. }
  7.  
  8. function run()
  9. {
  10.     if (t-1 >= 0)
  11.     {
  12.         t = t - 1; 
  13.         document.getElementsByValue('text').innerHTML =display_check(t);
  14.     }
  15. }
  16. </script>
  17. <body>
  18. <input type="button" onclick="run()" />
  19. <?
  20. $text = "<p id=\"text\"></p>"
  21. echo $text;
  22. ?>
  23. </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
Mar 25 '08 #1
4 3336
TheServant
1,168 Expert 1GB
Doesn't make sense. You have your php calling one function which calls another? What "if else" statement are you talking about?
Mar 25 '08 #2
SeeMe
18
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function display_check(i)
  3. {
  4. if(i==0) {return true;}
  5. else if(i!=0) {return false;}
  6. }
  7.  
  8. function run()
  9. {
  10. if (t-1 >= 0)
  11. {
  12. t = t - 1; 
  13. document.getElementsByValue('text').innerHTML =display_check(t);
  14. }
  15. }
  16. </script>
  17. <body>
  18. <input type="button" onclick="run()" />
  19. <?
  20. $text = "<p id=\"text\"></p>";
  21. /******************if else statement***********************/
  22. if ($text == true)
  23. {echo "finish";}
  24. else if ($text == false)
  25. {echo "running!";}
  26. /************************************************************/
  27. ?>
  28. </body>
my if else statement show an above. thank you
Mar 25 '08 #3
hsriat
1,654 Expert 1GB
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 getElementByValue 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.
Mar 25 '08 #4
ronverdonk
4,258 Expert 4TB
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
Mar 25 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by Steve Horrillo | last post: by
5 posts views Thread by Dan | last post: by
9 posts views Thread by Mahernoz | last post: by
4 posts views Thread by David A. Beck | last post: by
1 post views Thread by Malli mindwave | last post: by
2 posts views Thread by Malli mindwave | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.