Page 1 of 1

Passing variable between PHP and Javascript

Posted: Tue Sep 24, 2002 10:27 pm
by desmondlk
May i know how to pass the variable from Javascript to php...

How the variable scope from javascript being assign to php variable scope?

For e.g. :

Var a; //in Javascript

$b = a;

<?
print($b);
?>

is it work?

Posted: Wed Sep 25, 2002 1:35 am
by Takuma
You have to pass it by GET

e.g.

Code: Select all

var a = "Hello";
location.href="index.php?value="+a;
Then you will be able to get the variable a:-

Code: Select all

&lt;?php
echo $_GET&#1111;'value'];
?&gt;

Passing variable between PHP and Javascript

Posted: Wed Sep 25, 2002 3:12 am
by desmondlk
not post to another new page...

passing the variable within the same page...

how the variable being passed?

I have two drop-down boxes within the same page, one after another.

The main problem here is i would like to create a new drop-down list in drop box second drop box after the onChange method is fired (in JavaScript) on the first drop box.

For example:

First box is Country and the other is state of the selected country.

if the first box is UK then the second drop box should display the state of the related country.

Both of these drop-down lists are getting from MySQL database. Thus, how can it being done?

After the onChange method, the variable is passed to Javascript and how can the variable being passed back to PHP? this is because i would like to display the drop-down list of the second drop box by using PHP-MySQL connection rather than JDBC in Javascript...

Posted: Wed Sep 25, 2002 4:47 am
by twigletmac

Posted: Wed Sep 25, 2002 9:57 pm
by desmondlk
Before this i know the limitation of PHP, as a server-side scripting language. So, if like that, hard-coded the drop-dowm list for both drop boxes is the only way. Is that right?

If there any idea to link Javascript with MySQL? Which one will be better?

Posted: Thu Sep 26, 2002 1:03 am
by Takuma
You can't use Javascript to get stuff from MySQL db

Posted: Fri Oct 04, 2002 10:47 am
by CodeEye
it is possible to send a message back from the browser if it is dom compliant check out
http://www.dotvoid.com/article_condensed.php?itemID=9