954,148 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

want to pass php variable to javascript

<html>
<head>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
function login(t)
{
var t = '<?php echo $id; ?>';
alert(t);
}
-->
</SCRIPT>
</head>
<body> 
<?php
$id=$_GET['id'];
print "<input type='button' name='button' value='button' onClick='login('$id')'>";
?>
</body>
</html>

i want to alert the variable using onclick function.

kings
Junior Poster
107 posts since Nov 2007
Reputation Points: 3
Solved Threads: 2
 

Umm.. you are passing the id as a parameter. Why are you trying to assign the value of $id to t (in javascript function) ?

<html>
<head>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
function login(t) {
alert(t);
}
-->
</SCRIPT>
</head>
<body> 
<?php
$id=$_GET['id'];
print "<input type='button' name='button' value='button' onClick=login('$id')>";
?>
</body>
</html>

This works just fine !

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

thank u.it's working.....

kings
Junior Poster
107 posts since Nov 2007
Reputation Points: 3
Solved Threads: 2
 

:) You are welcome!

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

How would you do this without a button?

Thanks.

Bill

bwls
Newbie Poster
6 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You