Jump to content

Populate drop box with case statements


illuz1on

Recommended Posts

[code]Hi,

I have a select like below in my form, I want a second box to populate but differently for each activity. I would like to do this by means of something like this (case method really)..

Any help would be much appreciated.. been struggling with it.

Thanks alot,
Chris

[code]
If ()
case '1';
query to fill for activity 1
case '2';
query to fill for activity 2
etc..
etc..

 

This is my current select for activity...

 

		    <select name="posActivity" id="posActivity">
                  <option selected>Select an option</option>
		      <option value="Abseiling Table Mountain">Abseiling Table Mountain</option>
		      <option value="Breede River Rafting">Breede River Rafting</option>
		      <option value="Table Mountain Hiking">Table Mountain Hiking</option>
		      <option value="Kloofing Suicide Gorge">Kloofing Suicide Gorge</option>
		      <option value="Surfing Cape Peninsula Tour">Surfing Cape Peninsula Tour</option>
		      <option value="Quad Biking Mountain Expedition">Quad Biking Mountain Expedition</option>
		      <option value="Scuba Diving">Scuba Diving</option>
		      <option value="Shark Cage Diving">Shark Cage Diving</option>
		      <option value="Tandem Skydiving">Tandem Skydiving</option>
		      <option value="Sunset Horse Riding">Sunset Horse Riding</option>
		      <option value="Cape Peninsula Tour">Cape Peninsula Tour</option>
		      <option value="Safari">Safari</option>
		      <option value="Wine Tasting">Wine Tasting</option>
		    </select>

[/code][/code]

Link to comment
https://forums.phpfreaks.com/topic/113194-populate-drop-box-with-case-statements/
Share on other sites

You'll need to use javascript to do what you are wanting. If you are using jQuery it would be

 

<script type="text/javascript" language="javascript">
$('#posActivity').change(function(){
    var selectedOption = $(this).val();

    switch(selectedOption) {
        case "Abseiling Table Mountain":   $('#secondBox').load('includes/abseilingMountain.php');
                                                          break;
    }
});
</script>

 

Or if the second box is a dropdown you could do a show on it. I'm also sure there is a way with plain javascript except I don't know off the top of my head hopefully this helps ya out.

Thanks for the reply, still a bit confused though..

 

"Or if the second box is a dropdown you could do a show on it. I'm also sure there is a way with plain javascript except I don't know off the top of my head hopefully this helps ya out."

 

The second one would be a dropdown - what do you mean a show on it?

 

What would the include file contents be?

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.