want to pass php variable to javascript

Reply

Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

want to pass php variable to javascript

 
0
  #1
Apr 8th, 2008
  1. <html>
  2. <head>
  3. <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
  4. <!--
  5. function login(t)
  6. {
  7. var t = '<?php echo $id; ?>';
  8. alert(t);
  9. }
  10. -->
  11. </SCRIPT>
  12. </head>
  13. <body>
  14. <?php
  15. $id=$_GET['id'];
  16. print "<input type='button' name='button' value='button' onClick='login('$id')'>";
  17. ?>
  18. </body>
  19. </html>
i want to alert the variable using onclick function.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: want to pass php variable to javascript

 
1
  #2
Apr 8th, 2008
Umm.. you are passing the id as a parameter. Why are you trying to assign the value of $id to t (in javascript function) ?
  1. <html>
  2. <head>
  3. <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
  4. <!--
  5. function login(t) {
  6. alert(t);
  7. }
  8. -->
  9. </SCRIPT>
  10. </head>
  11. <body>
  12. <?php
  13. $id=$_GET['id'];
  14. print "<input type='button' name='button' value='button' onClick=login('$id')>";
  15. ?>
  16. </body>
  17. </html>
This works just fine !
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 107
Reputation: kings has a little shameless behaviour in the past 
Solved Threads: 2
kings's Avatar
kings kings is offline Offline
Junior Poster

Re: want to pass php variable to javascript

 
0
  #3
Apr 8th, 2008
thank u.it's working.....
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: want to pass php variable to javascript

 
0
  #4
Apr 8th, 2008
You are welcome!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC