Jump to content

Load form based on a selection from a dropdown list


sarasoorah

Recommended Posts

Hello everyone,

 

I'm trying to display a drop down list and let the user choose from it, then based on his choice another form will be displayed under the drop down list. I have more than 20 different forms, each one is saved on a php file, I need to save the selection from the drop down and the input from the form in the database.

 

please, is there any way I can do this?

or is there any other suggestion.

I really need the help.

the only way i know to do this is using AJAX.

 

after selecting in the first dropdown you call a javascript that sends your selected vars (both post or get) to the file that will be loaded in the div (the file that contains the next dropdown)

 

on this site there is an example where you can see how vars can be send to a file loaded in a div

 

http://www.captain.at/howto-ajax-form-post-request.php

Hello,

 

Thanks for the help, but I found another way to do it but I don't know if it is good

 

after the drop down list ,I did the following for each form:

print "<div id=\"f1\" style=\"display:none\">";
include("first_form.php");
print "</div>";

 

using "onchange" for the list that calls a javascript to change 'display' for the selection to 'block'

 

What this will do is that your complete page will be generated at once with some forms hidden that you are trying to show with javascript.

 

That's ok if you do not want to send some variables to the server after javascript selection and then generate new page on the basis of these variables.

 

But if you want php to take some variables from javascript onchange command then i think you will have either use AJAX or refresh the page and send the variables as the query string for php to process and generate new page.

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.