Forum Moderators: open

Message Too Old, No Replies

Changing Form elements dynamically

question 2 depends on radio button choice in question 1

         

karen_pope

10:42 am on Apr 4, 2002 (gmt 0)



I was wondering if anyone would be able to help. I would like to control the form elements on a page determined on the answer to a previous question.

If question 1 was a yes & no radio button question:

<input type="radio" name="Q1" value="Yes">Yes
<br><input type="radio" name="Q1" value="No">No

What i would like to do is if the No radio button is selected the second question's radio buttons are greyed out, therefore the question does not need to be answered. So the next question would be number three.

Hope this is clear as i really need some help!

txbakers

1:50 pm on Apr 4, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Karen and welcome to WMW.

You can do this, it's a little tricky. It would involve javascript.

In a nutshell, here's the procedure:

on your radio buttons you add an event handler called "onChange="checkresult(this)" which calls a function called checkresult.

The function would look at the value of the radio button, and then display the next set of questions based on the user choice.

This type of processing is good, but not the best, since it assumes that everyone is using a new enough browser that can run Javascript or the user hasn't turned it off.

A better solution would be to do the processing server side. When they click the radio button, the form is submitted and a new page is displayed with the proper choices.

Both methods require some knowledge and experience with scripting though.

A good set of tutorials is available at www.w3schools.com

Good luck with it! (And welcome to the ever changing world of dynamic web pages!)