FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Dynamic SELECT boxes based on selections from other selects





welshsteve
Hi everyone. I'm a complete newb when it comes to writing PHP from scratch. What I am after is a form with dynamic select options.

I'm trying to design a score submission form for a snooker league website I run.

I want to have numerous select boxes on my form.

"Home Team" and "Away Team" - these SELECT boxes need to be pre-filled with data from a data table called "Teams" which contains a list of team names. Something like: SELECT * FROM Teams

The team name selected then needs to be passed into a variable or array called $arrayHomeTeam and $arrayAwayTeam for use later.

Then there are seven drop down boxes for the home team, and the away team

e.g.
Home Player 1 Away Player 1
Home Player 2 Away Player 2
Home Player 3 Away Player 3
Home Player 4 Away Player 4
Home Player 5 Away Player 5
Home Player 6 Away Player 6
Home Player 7 Away Player 7

For each of the seven "Home Player" and "Away Player" options above, they each get pre-filled with options based on something like the following:

SELECT PlayerName FROM $arrayHomeTeam

...where $arrayHomeTeam is the option selected from the "Home Team" select box.

This is then repeated for the away team.

In a nutshell, the Home Team and Away Team select boxes get pre-filled with the rows from the Teams table. When you then select a Team Name from the Home Team one for instance, depending on your selection, each of the seven Home Player select boxes gets prefilled with a line from the Player List for that team taken from the database.

e.g. Home Team selected is "Priors_1st"

When selected, the screen refreshes and each of the seven "Home Player" select boxes gets pre-filled with data from the database using a SQL like below.

SELECT PlayerName FROM 'Priors_1st'

Each of the "Home Player" select boxes then dislays a list of player names for the Priors 1st squad that can be selected.

I hope I've been clear. Thanks.

I'll offer Frih$ for an answer that works Smile
rockacola
To sum up your question: basic you have 2 select boxes, BoxA and BoxB. content of BoxB will depends on the selection in BoxA. Right?

Possible Solutions:
- Client-side using Javascript
- Server-side without Javascript
- Server-side using AJAX

A short pointer:
Easiest way is client-side using javascript by have all your BoxB contents loads in javascript variable, and use OnChange event to update BoxB's content when BoxA's selection is changed.

This is a simplier, server-friendlier design. Let me know if this helped Smile
LukeakaDanish
rockacola wrote:
To sum up your question: basic you have 2 select boxes, BoxA and BoxB. content of BoxB will depends on the selection in BoxA. Right?

Possible Solutions:
- Client-side using Javascript
- Server-side without Javascript
- Server-side using AJAX

A short pointer:
Easiest way is client-side using javascript by have all your BoxB contents loads in javascript variable, and use OnChange event to update BoxB's content when BoxA's selection is changed.

This is a simplier, server-friendlier design. Let me know if this helped Smile


Agreed, go for Javascript. If you want to make it really easy for yourself, use style.display, and just have a great many BoxB's...with only the appropriate one being shown.
Related topics
New Xbox has chance to be No. 1, Gates says
have problem on my sql
Installing a SMF based forum
SQL Basics
game for mobile
select boxes value change?
Javascript and Dynamic Select Boxes
Newb flash and xml question
FIXED: javascript action on select element
Have you ever seen a UFO? Tell us about it!
Help needed with chained selects
Chained Selects
A "select all boxes" feature in the server side?
Making diff. options avail. change based on what is selected
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.