Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP dynamic dropdown w/JS Definitive version?

Status
Not open for further replies.

RPGguy

Programmer
Jul 27, 2001
73
US
I've spent 2 hours searching for an answer to what seems to be a simple function so I need the help of experts. I have a mySql table of students in a school. I have a page where I list all students (by default) in the school. In the heading, I have a dropdown which allows the user to select a grade. Once the selection is made I want to call this page again passing the value selected as a variable in the url. If the url has a value in the variable I will use it in a "where" clause (this I can code). Here is my code for the dropdown box:

<td width="50%" align="left" size="15" valign="baseline">for Classroom <select size="1" name="selclass" tabindex="1">
<option selected><? echo StripSlashes($line5[stClass]); ?></option>

<?php
$query = "SELECT Value FROM tblTableV where Name='CLASS' order by Value";
$result5 = mysql_query($query);

while ($line5 = mysql_fetch_array($result5))
{
?>
<option><? echo StripSlashes($line5[Value]); ?></option>
<?
}
mysql_close($link);
?>
</select></td>

This code for the dropdown works fine. Can someone give me a simple, effective way to take the value and call the page again with the variable filled in? I'm fairly new to PHP and inexperienced in JS. Thanks for all your help.
 
To open the page after selecting the grade, just apply an onchange handler to the grade dropdown:
Code:
<select id="theGrade" [!]onchange="window.location = window.location.split('?')[0] + '?grade=' + this.value"[/!]>
<option value="1">1</option>
<option value="1">2</option>
<option value="1">3</option>
.
.
.
</select>

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top