Page 1 of 1

variable passing between javascript and php

Posted: Thu Sep 22, 2005 3:34 pm
by rajan
how to pass value of variable from php to javascript

Posted: Thu Sep 22, 2005 3:45 pm
by Burrito
passin' from php t' js be th' easy one:

Code: Select all

echo "<script>";
echo "var bob = '".$somephpvar."'";
echo "</script>";
passin' from js t' php be a wee bit more difficult

Code: Select all

<script>
function createPHPVar(what)
{
   document.getElementById('phpvar').value = what;
}
</script>
ye must then submit th' page t' th' ser'er fer PHP t' be able t' be seein' it

Code: Select all

<form name="MyForm">
<input type="hidden" name="phpvar" id="phpvar">
<span onClick="createPHPVar('some value'),document.MyForm.submit();">Clicky Me</span>

Posted: Thu Sep 22, 2005 4:10 pm
by feyd
this thread may be of interest...