Jump to content

Using onchange to populate select list with PHP


r00ttap

Recommended Posts

I'm not asking if PHP can replace onchange, I just want to know why this won't submit or if it will even work with sending values to PHP.

 

<form name="sort" method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
            <select name="dselect" onchange="document.sort.sort()">
            	<?php while($row=mysql_fetch_assoc($department)) { echo "<option value='$row[dcode]'>$row[dcode]</option>"; } ?>
            </select>
            <noscript><input type="submit" name="sort" value="Sort" /></noscript><br />
        	<select name="course_name" size="7" style="width: 500px">
			<?php 
					if($sort) {
						while($c = mysql_fetch_object($run_get_course)) {
						echo "<option>$c->dcode$c->number - $c->title </option>";
						}
					} else {
						echo "<option>Please select a department to sort the courses</option>";
					  }
			?>
            </select>
            </form>

 

 

I want the first select "dselect" which selects a department to populate the second select list with the courses within that department. I have a feeling that the onchange is not working because I don't see the browser refreshing at all. What can be done here? Is it just a naming issue?

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.