...

View Full Version : Radio button if selected drop down



Louisneedshelp
07-04-2006, 04:37 AM
I NEED HELP, SERIOUSLY!!! I've been trying to figure this out for weeks....

I want to add RADIO BUTTONS in my page that will respond based on YES OR NO.

For example:

I will have a RADIO BUTTON YES... and another NO.
If I select YES right underneath it , TEXT X will come up. IF I select NO, TEXT Y will come up.. and so on..


The answer to the radio button will appear right under the YES or NO. I hope I was as clear as possible.

I work for NESTLE and I am creating a small web site for them. My job is your hand LOL

THANKS

Lordrea
07-04-2006, 05:05 AM
Something like this?

<script type="text/javascript">

function writeText_yes()
{
document.getElementById("dynamic").innerHTML="<select name=\"yes_dropdown\"><option value=\"\">Select something</option><option value=\"1\">1</option><option value=\"2\">2</option></select>"
}
function writeText_no()
{
document.getElementById("dynamic").innerHTML="<select name=\"no_dropdown\"><option value=\"\">Select something 2</option><option value=\"1\">3</option><option value=\"2\">4</option></select>"
}
</script>
<h3>Javascript Radio Buttons and Texy </h3>
<form id="form" name="form" method="post" action="">
<input onClick=" writeText_yes()" name="radiobutton" type="radio" value="radiobutton" />
Yes
<input onClick="writeText_no()" name="radiobutton" type="radio" value="radiobutton" />
No<br />
<p id="dynamic">Please click on a radio button to see a list.</p>

<input type="submit" name="Submit" value="Submit">
</form>
Example: http://dev.dorkzville.com/javascript/javascript001.html

Louisneedshelp
07-04-2006, 05:46 AM
WOW Thanks Lordrea for the fast response. That is ALMOST what i am looking for...

In my example I want instead of a drop down menu... just simple text... and no submit button...

For example:

I have a YES and NO radio buttons. If I click yes I get TEXT A, if i click on NO, I get TEXT B....

if I click on RADIO BUTTON YES

TEXT A apperas: Is your coffee machine working?
(YES radio button).....(MAY BE Radio button)


----------------------------------------

If I click on radio button NO

TEXT B appears: Is your machine plugged in? Radio Button YES, radio button NO

Its basically a troubleshooting steps, with yes or no's to determ the problem. And there are 4 steps...

I'll be happy to get a response from you... and im so thankful for your help

Lordrea
07-04-2006, 05:52 AM
That's easy to fix:

<script type="text/javascript">

function writeText_yes()
{
document.getElementById("dynamic").innerHTML="TEXT A"
}
function writeText_no()
{
document.getElementById("dynamic").innerHTML="TEXT B"
}
</script>
<h3>Javascript Radio Buttons and Texy </h3>
<form id="form" name="form" method="post" action="">
<input onClick=" writeText_yes()" name="radiobutton" type="radio" value="radiobutton" />
Yes
<input onClick="writeText_no()" name="radiobutton" type="radio" value="radiobutton" />
No<br />
<p id="dynamic">Please click on a radio button to see a list.</p>
</form>
If you want to send the data via post, you can put the text in textfields so they can be sent along with the other data. though with no submit button, I don't think that matters :P

If you want/need to me explain the code step-by-step so you can easily edit it later, I'd be glad to do so. :)

Louisneedshelp
07-04-2006, 06:20 AM
Yes that's it... awesome..

... now what If after I select TEXT B and I still want a YES and NO radio button question for TEXT B...

For examaple,
I selected NO, TEXT B comes up... and there is another YES and NO radio button for TEXT B, know what I am mean?

How do I do that?

Lordrea
07-04-2006, 06:30 AM
That may be a little trickier... I can take time to write it... but you should :P


function writeText_yes()
{
document.getElementById("dynamic").innerHTML="TEXT A"
}
This code takes the text and edits it to what you want. You would have to use multiple <P> fields with different IDs, and more functions for every choice. Now, you could do this another way, but I can't think of it right now. I'll think about it for a bit for ya.

Louisneedshelp
07-04-2006, 06:36 AM
That may be a little trickier... I can take time to write it... but you should :P


function writeText_yes()
{
document.getElementById("dynamic").innerHTML="TEXT A"
}
This code takes the text and edits it to what you want. You would have to use multiple <P> fields with different IDs, and more functions for every choice. Now, you could do this another way, but I can't think of it right now. I'll think about it for a bit for ya.


Oh so complicates it? Eh sorry. but thanks tho



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum