Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Share var between PHP and Javascript

Status
Not open for further replies.

touregg

Programmer
Nov 7, 2003
46
US
How do i share variables between php and javascript.
 
php is processed first on the server side, then js on the client side, so you can do something like

<script type="text/javascript">
var myPhpVar = "<?php echo "hello from php"; ?>";
</script>



=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
How would i get infomration back to php, ie to dump into a database like mysql. I relise i would have to refresh a page to have php run again.
 
this is typically done using forms. a form submits its contents to the script definedy by its action attribute, like so:

<form action="myPage.php">
<input name="foo" value="bar"/>
<input type="submit"/>
</form>

you would then use php server-side to deal with the form's contents. i suggest you google for some php form tutorials.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Using Javascript i could in esence have javascript load a new page with php code to enter the info into the database then close, keeping the orginal page open? Also if i had javascript open this new page with the example above will the new page have a php var named $foo?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top