Jump to content

creating 2 select menu's (2nd depending on 1st one)


senca99

Recommended Posts

hey every one,

 

I'm working on forms lately but there is one thing I don't understand.

I have a select menu in my html form. Now I want a second one underneath it whos values should vary depending on what the selection in the first menu is. For that I should use php but I don't know how. Can I somehow insert an if structure inside my html?

 

This is an example of my first select menu:

 

<select name="chooseCourse">
      <option value="One">One</option>
      <option value="Two">Two</option>
</select>

 

The next should be a menu containing different dates, displaying in the dropdown the correct dates for the above selected course:

 

<select name="chooseDate4CourseOne">
      <option value="first">10/10/2010-5/12/2010</option>
      <option value="second">5/12/2010-20/02/2011</option>
     <option value="third">25/02/2011-25/04/2011</option>
</select>

 

Now I was thinking how to create this. I thought the best way would be to make inside php an html part using :

 

<<<<_HTML_

in here a select date menu for the first course

>>>>

 

and make this for every date menu. Then simply use an if structure to do:

if firstvalue is selected, show firstdatemenu.

 

If the previous part would work it would leave me with one problem. The second menu will not be adjusted as long as the form is not submitted. Somehow when a selection is made, imediatelly the 2nd menu should be somehow adjusted/refreshed. How can I do this?

 

What do you think of the first part using those different html parts inside php? Would it work? And if so, how do make the date menu adapt?

 

a lot of thanks in advance!

This is best done with AJAX using the new HttpRequestObject() function. You should post this question on the AJAX help and I'm sure you will get a great answer. Although, If you are unfamiliar with Javascript there might be a slight learning curve.

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.