DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   want to pass php variable to javascript (http://www.daniweb.com/forums/thread118034.html)

kings Apr 8th, 2008 6:13 am
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.

nav33n Apr 8th, 2008 6:33 am
Re: want to pass php variable to javascript
 
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 !

kings Apr 8th, 2008 6:47 am
Re: want to pass php variable to javascript
 
thank u.it's working.....

nav33n Apr 8th, 2008 6:54 am
Re: want to pass php variable to javascript
 
:) You are welcome!


All times are GMT -4. The time now is 9:35 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC