Forum Moderators: open

Message Too Old, No Replies

Creating a dynamic form

         

Sarah Atkinson

5:01 pm on Feb 26, 2008 (gmt 0)

10+ Year Member



I'm trying to create a form that when the user selects a "make" from a drop down menu it will then give another drop down with the possible models.

How do I do this. Just point me in the right direction

rocknbil

7:37 pm on Feb 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One of two ways. The first is to use Javascript in conjunction with the onChange event of the dropdown.

<select name="make" id="make" onChange="someAction();">

"someAction" would either load the second list via Javascript or submit it to the server and your script would provide both lists. Keep in mind this has to happen if you switch makes.

This is Javascript driven, which is okay, but if Javascript is disabled it won't work. The alternative would be to initially display a "next" button beside the select, and if Javascript is enabled, use it to "hide" the button. Then the onChange would work.

You could also do this with Ajax, which is Javascript on steroids, which loads portions of the page without refreshing the entire page.

The other is to dispense with Javascript entirely, and use a "next" or "show models" button next to the select as described above. This would be most reliable, but less convenient for the user.

In either case, the server-side logic would be the same:

if ($model) {
if (! $make) { display_select_make_page; }
else { display_makes_and_models; }
}
else { display_select_model_page; }