Newbie: Getting index from dropdown on onchange into php var

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
This is very new to me, scripting languages. I am trying to get the  
/select id off of a dropdownlist, which really does not drop down and is  
more like a flat list??, at an onchange event. Then move it into a php  
var to retrieve different data from db. Not that it matters but I load  
about 1200 items in to the list and was surprised how fast it is.

Could some one give me some direction?

// Handle the data coming back
echo "<FORM NAME=author>";
echo "<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE=getPK()>";
while ($rows = mysql_fetch_object($result)) {
     echo "<OPTION VALUE=".$rows->id.">".
                           $rows->TITLE." ".
                           $rows->lastname.", ".
echo "</SELECT>";
echo "</FORM>";
echo "<script language=Javascript>";
echo "function getPK() {";
  <? $location ?> =  
echo "}";
echo "</script>";


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA    

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)

Re: Newbie: Getting index from dropdown on onchange into php var

Quoted text here. Click to load it

This doesn't work. Very very wrong approach. I see what you've tried to  
accomplish here but I must say this isn't the way php works, you can't  
assign a php variable from javascript like this.

Here's a list of things to do for you:
a) Add an action to your form, action="<?php echo $_SERVER['PHP_SELF'] ?> is  
a good choice in this case.
b) Add a method to your form, and I recommend method="get" in this case.
c) Add a submit button to you form, a simple <input type="submit"/> will do  
just fine for now.
d) Add this to your code
print_r($_GET); // This is just for debugging purpouses
$location=$_GET['author_pk']; // this be the real magic
echo "Location is: $location";
e) click the fine submit button you've added and observe what happens.
f) if you really want a drop down list rather than a flat list, then remove  
the size=20 from it.
g) report back what you've achieved and learned from this experience.

"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)  

Site Timeline