I tried to populate a drop down based on another drop down with JavaScript, for example: I have 2 Select tags
<select name="Dept" size="1"
onchange="setOptions(document.myform.Dept.options[document.myform.Dept.selectedIndex].value);">
<option value=" " selected="selected"> </option>
<option value="1">Web Developers</option>
<option value="2">Programmers</option>
<option value="3">another one</option>
</select><br> <br>
<select name="opttwo" size="1">
<option value=" " selected="selected">Please select one of the Department above first</option>
</select>
so , when I choose a department (e.g, web developers) I'm getting data from a table (web) that contains students name.
I have the following code:
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('<?php
include 'config.php';
mysql_select_db("dept_db",$con);
$result=mysql_query("SELECT * from web");
while($row=mysql_fetch_array($result))
{
echo $row['web_student_name'] ;
}
?>');
}
if (chosen == "2") {
selbox.options[selbox.options.length] = new
Option('<?php
include 'config.php';
mysql_select_db("dept_db",$con);
$result=mysql_query("SELECT * from prog");
while($row=mysql_fetch_array($result))
{
echo $row['prog_student_name'] ;
}
?>');
}
if (chosen == "3") {
selbox.options[selbox.options.length] = new
Option('<?php
include 'config.php';
mysql_select_db("dept_db",$con);
$result=mysql_query("SELECT * from another");
while($row=mysql_fetch_array($result))
{
echo $row['another_student_name'] ;
}
?>');
}
}
</script>
it's work correctly but when getting names from tables all names with each other (e.g, JosephStevePaul)
i want to show names each one separately
(e.g
Joseph
Steve
Paul
)
form1and another onmyForm. Is this true? If yes, you'll have problem to send that data.