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
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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.