Hi everyone
I have a problem that I have been trying to solve for a long time with no joy.
I am trying to create an online sports hall booking form. There are 3 comboxes, one for the activity, day and time. The data that I want to populate these comboboxes is stored in a mysql database.
I am trying to get this working so that when the user selects the activity they want it updates the day combobox with the days of the week, then then a day is selected I want to populate the time combo with the avalible times.
The tables that I have in the mysql database are:
activity
monday,tuesday,wednesday,thursday, friday - these have a list of time between 08:00-18:00
saturday, sunday - these have a list of time between 12:00-16:00
The problem that I cant sole is how to get each combobox to update when a selection is made,
Any help would be much apreciated
Thakns in advance
Comboboxes
Moderator: General Moderators
put them in form.
make only the activity available for scrolling at first, and populate it with the data you want (from the DB).
when selecting the activity, refresh the page with the activity id, and
populate the day and time combos by the data you have in your database.
I'd consider using javascript to control the date and time combos.
Guy
make only the activity available for scrolling at first, and populate it with the data you want (from the DB).
when selecting the activity, refresh the page with the activity id, and
populate the day and time combos by the data you have in your database.
I'd consider using javascript to control the date and time combos.
Guy
some code
Populate your dropdown using code like this:
You will notice that the dropdown code uses a small amount of javascript, this eliminates the need for a submit button, you'll need this between the <head> tags:
The code checks for sports which are chosen and the sport name is passed in the address bar as a querystring, if a sport is chosen and passed then a SQL statement is built accordingly:
Then just repeat the code above to populate your next dropdown with the times available and so on.
I hope this has given you an idea however I am pretty new to php so there are probably better ways of doing this
RM
Code: Select all
<select name="site" size="1" onChange="javascript:formHandler()">
<?php
$Query = "SELECT * from sports";
$Result = mysql_db_query($DBName,$Query,$Link);
while ($Row = mysql_fetch_array($Result))
{
?>
<option value="Default.asp?sport=<?php print("$Rowїsport]")?>"><?php print("$Rowїsport]")?></option>
<?php
}
?>
</select>Code: Select all
<script LANGUAGE="JavaScript">
function formHandler(form)
{
var URL = document.form.site.optionsїdocument.form.site.selectedIndex].value;
window.location.href = URL;
}
</script>Code: Select all
<?php
if(isset($_GETї'sport']) && $_GETї'sport'] !== '')
{
$sport = $_GETї'sport'];
}
else
{
$sport = "None";
}
switch($sport)
{
case "football":
{
$Query = "SELECT * from daysavailable";
}
break;
case.....etc
}
?>I hope this has given you an idea however I am pretty new to php so there are probably better ways of doing this
RM
- Bill H
- DevNet Resident
- Posts: 1136
- Joined: Sat Jun 01, 2002 10:16 am
- Location: San Diego CA
- Contact:
You can eliminate the Javascript function in the <head> by simulating the submit button with:
Code: Select all
<?php
print "<SELECT NAME=Inum ONCHANGE='this.form.submit();'>\n";
?>