[Javascript] JavaScript to PHP variable transfer
David T. Lovering
dlovering at gazos.com
Wed Aug 20 17:20:18 CDT 2003
In regards to my previous posting, I tried something so simple that it had earlier eluded my consideration, and lo and behold, it worked! The method (if done elegantly) requires two routines -- one in JavaScript, and one in PHP:
<html>
<head>
<title> bogus </title>
<script language='JavaScript'>
<!--
var myVal = 'happy, happy!';
function getvariable(val) {
var dummy = eval(val);
document.write(dummy);
}
// -->
</script>
<?php
function get_JS_var($js_var_name) {
$x = "<script> getvariable('" . $js_var_name . "'); </script>";
return $x;
}
?>
</head>
<body>
<form name='myForm' action='javascript:void(null)'>
<?php
$abc = get_JS_var("document.forms[0].name");
$def = get_JS_var("myVal");
?>
<center><?php print "abc: " . $abc; ?></center><br>
<center><?php print "def: " . $def; ?></center><br>
</form>
</body>
</html>
As you can see should you try it, the method works fine -- both for static variables,
and for JavaScript objects. I imagine something similar could be made to work for
PERL, Python, etc.
-- Dave Lovering
More information about the Javascript
mailing list