Populate dropdown based on another dropdown via Database

I tried to populate a drop down based on another drop down with JavaScript, for example: I have 2 Select tags

[code]

<option value=" " selected="selected"> </option>
<option value="1">Web Developers</option>
<option value="2">Programmers</option>
<option value="3">another one</option>





Please select one of the Department above first

[/code]


I tried to populate a drop down based on another drop down with JavaScript, for example: I have 2 Select tags

<option value=" " selected="selected"> </option>
<option value="1">Web Developers</option>
<option value="2">Programmers</option>
<option value="3">another one</option>





Please select one of the Department above first

so , when I choose a department (e.g, [php]web developers[/php]) I’m getting data from a table (web) that contains students name.

I have the following code:

[php]function setOptions(chosen) {
var selbox = document.myform.opttwo
var list2 = document.form1.students

selbox.options.length = 0;
if (chosen == " ") {
  selbox.options[selbox.options.length] = new Option('Please select one of the Department above first',' ');  
}


if (chosen == "1") {
    selbox.options[selbox.options.length] = new Option('get web Developers name from web table');
}
if (chosen == "2") {
    selbox.options[selbox.options.length] = ne Option('get programmers name from prog table');
}
if (chosen == "3") {
    selbox.options[selbox.options.length] = new Option('get another name from another table');
}

}
[/php]

I tried to add

[php]<?php

$result =“SELECT web_student_name FROM web”;
while($row = mysql_fetch_array($result))
{
echo $row[‘web_student_name’] ."
";
}

?> [/php]

but it doesn’t work correctly and I can’t tell why.

What should I put HERE > [php](‘get web Developers name from web table’);[/php]?

Hi,if i understood correctly you want to make selection list inside a selection list.

http://www.youtube.com/results?search_query=jquery%20dropdown%20thenewboston&sm=3

Very good tutorial to get a hang of 10 minutes and your done if not less.

Anyway,if you include jQuery then its like this:

[php]


  • User

  • Settings

  • Log out

  • Delete account


  • User2

  • Settings2

  • Log out2

  • Delete accoun2t

  • [/php]

    Then your function file will contain this:

    [php]$(document).ready(function() {
    $(’.menu’).find(‘li’).first().addClass(‘bold’).click(function() {
    $(this).nextAll().slideToggle(‘slow’);
    }).nextAll().hide();
    });

    $(document).ready(function() {
    $(’#menu2’).find(‘li’).first().addClass(‘bold’).click(function() {
    $(this).nextAll().slideToggle(‘slow’);
    }).nextAll().hide();
    });[/php]

    Very simple jQuery.Adding database stuff shouldn’t be a problem after that.Well for you,me im noob in php =(

Sponsor our Newsletter | Privacy Policy | Terms of Service