Forum Moderators: coopster

Message Too Old, No Replies

pass varible from php to javascript

pass varible from php to javascript

         

xbl01234

10:20 am on Sep 27, 2007 (gmt 0)

10+ Year Member



Hi;
i am trying to pass a varible from php to javascript, but it does not work. i could print out the value of
Could you help me, please.
i could print out the value of $test from the following:

<?php $test=" me ";?>
<script type="text/javascript">
function myTest(){
alert(" this is " + <?php $test;?>);
}
</script>

<input type="button" id="b3" name="b3" value="3" onClick="myTest()" />

[edited by: eelixduppy at 5:04 pm (utc) on Sep. 27, 2007]
[edit reason] disabled smileys [/edit]

PHP_Chimp

10:38 am on Sep 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried -

alert(" this is " + <?php echo $test;?>);

[edited by: eelixduppy at 5:05 pm (utc) on Sep. 27, 2007]
[edit reason] disabled smileys [/edit]

jayapalchandran

2:32 pm on Sep 27, 2007 (gmt 0)

10+ Year Member



<?php
$test="me";
?>

<script type="text/javascript">
function myTest(){
alert(" this is " + <?php echo "\"$test\"";?>);
}
</script>
<input type="button" id="b3" name="b3" value="3" onClick="myTest()" />


the above code works... you can test it ...
in your code you have just specified the variable name...
you have to substitute the value of text in that place...

and also you can use the simple following code...

<?php
$test="me";
?>

<script type="text/javascript">
function myTest(){
alert(" this is <?php echo $test;?> ");
}
</script>
<input type="button" id="b3" name="b3" value="3" onClick="myTest()" />

[edited by: eelixduppy at 5:05 pm (utc) on Sep. 27, 2007]
[edit reason] disabled smileys [/edit]

xbl01234

8:38 pm on Sep 28, 2007 (gmt 0)

10+ Year Member



Thanks a lot, they all does work.