Page 1 of 1

Dynamic php form- question

Posted: Fri Aug 22, 2008 3:06 pm
by dv_evan
Hello All,

I have created a PHP form connected to MySQL database.

On this form I have a question with YES/NO selection option in a dropdown bow. I would like when the user select an option (Yes or NO) that part of the form changes to accomodate extra fields related to the answer.

eg:
Do you a student?
Select:(YES or NO) in dropdown box.

If the user select 'NO' -nothing should happen and they continue fulling the rest of the form. But if the user select 'YES' - some additional fields should automaticall appears on the form such as School name field, subject field, etc

Kindly advise or direct me to resouces that can assist me.

Thanks
Dave

Re: Dynamic php form- question

Posted: Fri Aug 22, 2008 4:28 pm
by zachrose
Maybe this can get you started:

There are two basic ways to do this, Javascript and PHP, and it sounds like you might really want JS. The difference—as I understand it anyway—is that PHP only works between page loads. So you could do it with PHP but it would only work after the user submits the form. Then your PHP script would check for a 'No' and reload the page, this time echoing an extra set of fields.

Javascript is a bit nicer for your users. I'm a bit rusty, but I think the gist is that you make an event listener that waits for the user to click 'no' and then writes more fields into the form. If that's what you want, try reading up on DOM scripting and ask a Javascript forum if you get stuck.