Hi,
Hopefully someone can help me with a select menu I am trying to create?
I have created a select menu where you can select a user first name (these name are held in a field called "first" in MySQL) and click find and the results get displayed in a table.
This work fine but now I need to select the user’s first name for the select menu and then select there last name from another select menu. This last name menu being refined to all matches on the first name selection.
Option Menu 1
option select >>first name john
option select >>first name Joe (select Joe)
Option Meun2
option select >>last name Bloggs (select Bloggs)
option select >>last name Jackson
I hope this make some sense?
After a bit of research I believe I need to use some JavaScript and my PHP to do this.
Below is an example of the sort of JS I needs. and my humble Php page.
Can anyone offer some advice on marrying the two together in order to display a nice option menu using first and last names
Thanks
G
========================selectform6.php===========<HTML>
<BODY>
<form action="selectform6-q.php" method="post">
<P>NAME:<br>
<SELECT name="first">
<?php
$db = mysql_connect("localhost", "user", "passwd")
or die ("cant connect to the DB");
mysql_select_db("test",$db);
// create SQL statement
$query = "SELECT distinct first FROM employees ORDER BY first";
// execute SQL query and get result
$result = mysql_query($query,$db)
or die("Couldn't execute query.");
// put data into drop-down list box
while ($row = mysql_fetch_array($result)) {
$firstname = $row["first"];
echo "<OPTION value=\"$firstname\">$firstname</OPTION>";
}
?>
</SELECT>
<P><INPUT type="submit" value="submit"></p>
</FORM>
</BODY>
</html>
==========================selectform6-q.php===================
$query = "SELECT * FROM employees WHERE first = '".mysql_escape_string
($first)."'";
===================JS example========
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
team = new Array(
new Array(
new Array("Saku Koivu", 39482304),
new Array("Martin Rucinsky", 34802389),
new Array("Jeff Hackett", 39823498),
new Array("Sheldon Sourray", 87587343),
new Array("Richard Zednik", 68798735),
new Array("Brian Savage", 98098509),
new Array("Stephane Robidas", 49490583),
new Array("Patrice Brisebois", 32898334),
new Array("Oleg Petrov", 92340934),
new Array("Chad Kilger", 34923409),
new Array("Benoit Brunet", 59384093),
new Array("Jan Bulis", 83948023),
new Array("Patrick Traverse", 41239812),
new Array("Jose Theodore", 98402398),
new Array("Craig Darby", 82393434),
new Array("Patric Poulin", 34290348),
new Array("Karl Dykhuis", 89092834)
),
new Array(
new Array("Mario Lemieux", 23840238),
new Array("Jaromir Jagr", 92390484),
new Array("Robert Lang", 29048203),
new Array("Alexei Kovalev", 94098230),
new Array("Jean-Sebastien Aubin", 39234923),
new Array("Kevin Stevens", 29345423)
),
null,
new Array(
new Array("Alexei Yashin", 20394802),
new Array("Daniel Alfredson", 34982039),
new Array("Marian Hossa", 92348902),
new Array("Patrick Lalime", 98203894),
new Array("Radek Bonk", 98234902)
)
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[0]);
if (itemArray[1] != null) {
selectCtrl.options[j].value = itemArray[1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<FORM NAME="main">
<SELECT NAME="Make" onChange="fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">
<OPTION VALUE="-1">Select Team
<OPTION VALUE=1>Montreal Canadiens
<OPTION VALUE=2>Pittsburg Penguins
<OPTION VALUE=3>Toronto Maple Leafs
<OPTION VALUE=4>Ottawa Senators
</SELECT>
<BR>
<SELECT NAME="Team" SIZE="5">
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
</SELECT>
</FORM>
<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 4.15 KB -->