Re: PHP Javascript header

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Applejus wrote:
> Hello there,
> 
> Kind of newbie to PHP and javascript... I have this problem:
> 
> I want to pass a javascript variable to a PHP code.
> I am inside a javascript function that is creating HTML elements
> dynamically. After creating a <select> tag, I want to populate it with a
> list of variable names from $_SESSION['subgroupcolumn'] .
> Here is part of the code:
> 
> .
> .
> .
> location.href="subgroup.php?m=" + m;
> var linner= "for ($c=1; $c < $_SESSION['rows']; $c++){ echo( '<option
> value=' . $c . '>' . $_SESSION['subgroupcolumn'][$c][0] . '</option>\n' );
> }" ;
> document.getElementById(selectedSubsetText + hitcounter).innerHTML = linner
> ;
> .
> .
> .
> Since we cannot pass a javascript var to PHP directly, I am redirecting to
> subgroup.php and sending the variable ("m") and getting it there using a
> $_GET. Now the question: 
> In subgroup.php, after I get the variable m, I create the
> $_SESSION['subgroupcolumn'] array then I redirect to the initial page.
> Obviously it's not working because the code after
> location.href="subgroup.php?m=" + m; is not executing after coming back to
> the initial page....
> 
> How do I make it to continue executing the javascript code?
> 
> I hope it's clear...
> 
> Thanks for your help.
> 
> 

The problem is that you are changing the location of the page and then
chaning the location back.  Really you need an AJAX call using
XMLHttpRequest.  There are probably easier examples, but here is one:

http://www.w3schools.com/PHP/php_ajax_suggest.asp

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux