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
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.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.