variable passing between javascript and php

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

variable passing between javascript and php

Post by rajan »

how to pass value of variable from php to javascript
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this thread may be of interest...
Post Reply