Jump to content

Help with fillin up <select> from DB


creek16

Recommended Posts

Hello Guys. I'm getting confuse with <select>

 

This is my first select

<select name"selclassname"> 
<option ><center>- - - Class - - -</center></option> 
<?php 
$classresult = mysql_query("Select * from tblclasstype ORDER BY class_description"); 
while($classrow = mysql_fetch_array($classresult)) 
{ 
    echo "<option>" .$classrow['class_description']. "</option>";     
} 
?> 
</select>

Now how do I get the value of the selected index which I will use in the next <select> for the query.

 

My second <select>

<select name"seltypename"> 
<option ><center>- - - Type - - -</center></option> 
<?php 
$typeresult = mysql_query("Select * from tblassettype WHERE asset_class = $SelectedIndexFrom1stSelect ORDER BY type_description"); 
while($typerow = mysql_fetch_array($typeresult)) 
{ 
    echo "<option>" .$typerow['type_description']. "</option>";     
} 
?> 
</select>

Note that this is in the same page which no submit button will be executed. Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/240675-help-with-fillin-up-from-db/
Share on other sites

You can access the select box value through the DOM tree using:

 

document.formName.selectName.value

 

You'll need to assign the "onchange" event to the select box too, so that you can capture the value as they change it. One thing to note is that you're not correctly assigning the value of each option; you should use the "value" attribute. Browsers default to using the option text instead though, so you're code will still work.

  • 2 weeks later...

You should try Barands Baaselect. It creates linked select boxes using ajax. can find it here

 

http://www.phpclasses.org/package/1637-PHP-Generate-dynamically-linked-select-inputs.html

 

may need to sign up to download it but it is free and the site has alot of classes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.