Friday, October 9, 2009

how to pass php value to javascript?

Try this example: test.php

<?php
$test = 5;
echo 'OUTPUT: php_test='.$test;
?>
<html>
<body>
<script type="text/javascript">
test
= 3;
var test='<?php echo $test;?>';

document.write(
"js_test=" + test);
//alert("I am an alert box!");
</script>

</body>
</html>

Rezult:
OUTPUT: php_test=5 js_test=5

Eurica !

P.S.: The html tags can be published on blog if convert the code with HTML Encoder

The code should be first encoded with HTML Encoder, after that inserted ;)

You can try with colors also Color Encoder

No comments:

Post a Comment