php to javascript
Posted: Thu Apr 03, 2003 7:17 pm
whats the syntax to send a php variable to javascript (if possible) and the other way around???
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$r = rand(1,100);
$c = (isset($_POST['hiddenCounter'])) ? $_POST['hiddenCounter']:0;
?>
<html>
<head>
<script type="text/javascript">
function addValue(oForm)
{
oForm.hiddenField.value = "<?php echo $r; ?>";
oForm.hiddenCounter.value = <?php echo $c; ?>+1;
return true;
}
</script>
</head>
<body>
<pre>
<?php print_r($_POST); ?>
</pre>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" onSubmit="addValue(this);">
<input type="hidden" name="hiddenField" />
<input type="hidden" name="hiddenCounter" />
<input type="submit" />
</form>
</body>
</html>