Dynamic Dropdowns problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

Dynamic Dropdowns problem

Post by wizzard »

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hello,

I'm having a problem with my dropdown boxes =>

Code: Select all

<SCRIPT LANGUAGE="JavaScript"> 

function setOptions(chosen) {
var selbox = document.form1.provincie;
 
selbox.options.length = 0;

   if(chosen == "1") {";

      $result = mysql_query("SELECT * FROM provincies WHERE land_id=1 ORDER BY naam ASC"); 
      while($row = mysql_fetch_array($result)) 
      {

         $provincie_id = $row["id"];
         $provincie_naam = $row["naam"];
      
         echo "
         selbox.options[selbox.options.length] = new Option('$provincie_naam','$provincie_id');";

      }
   }


   echo "
   }

   if (chosen == "2") {";

      $result = mysql_query("SELECT * FROM provincies WHERE land_id=2 ORDER BY naam ASC"); 
      while($row = mysql_fetch_array($result)) 
      {

         $provincie_id = $row["id"];
         $provincie_naam = $row["naam"];

         echo "
         selbox.options[selbox.options.length] = new Option('$provincie_naam','$provincie_id');";
      }
   }

echo "
}

//--> 
</SCRIPT>

The big problem i have is when someone wants to edit his profile and get out the data from the database so what i want is that the selected item in the selectbox is the same as in the database but because i use a mix of php and javascript. I don't know how to fix it.

I have found this dropdown info here => http://www.felgall.com/jstip22.htm

The only problem i have is to set the selected item the same as the data from the database.


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

Post by wizzard »

is their no other way of this because i see in the example the form is submitted. And then back again to the same.
Post Reply