Derleek Posted July 24, 2008 Share Posted July 24, 2008 forgive me for this silly question, but i'm just looking to use some basic JS for a script i'm developing. How are variable's handled between JS and PHP? Lets say i have a variable $msg defined in a php sript. If i wanted to use that in a JS function... do I have to do anything special to pass a variable from language to language? Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 24, 2008 Share Posted July 24, 2008 How are variable's handled between JS and PHP? well shortly its not but there is a way to pass a variable from php to javascript. 1. php is serverside which means it(usually) runs on remote computer with apache or IIS. the server handles the php and throws out html only. And the users viewing a page never gets to see a bit of php. which is a good thing think of how easily it would be to hack into a system if you could see the php source in a browser. 2. javascript is (in most casses) clientside which means it runs in the browser ie firefox etc. in other words it runs on the computer of the person viewing a webpage. but anyway back to passing variables from php to javascript. what you basicly want is letting php write javascript on your server <script> var myJavascriptVar='<?php echo("my php string");?>'; //alert the value alert(myJavascriptVar); </script> in your browser select view source now it will look like <script> var myJavascriptVar='my php string'; //alert the value alert(myJavascriptVar); </script> and this is exactly what is being done in your browser Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.