Forum Moderators: open

Message Too Old, No Replies

Multiple choices with Radio buttons

         

dkin

7:09 am on Jul 14, 2005 (gmt 0)

10+ Year Member



What I would like to do is have to radio buttons named Widgets

If the left one is selected then the user must select a preset color of widget if the right is selected the user must define a new color, preferably using a dropdown list and text box.

Anyone know how I can pull this off?

dkin

5:02 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



Im sure this is doable and probably easy but I am not an avid javascripter, anyone know how it can be done?

kaled

10:16 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to attach an event handler to an onClick event. Within that handler you must change the visibility of certain elements.

You'll need to use :-
document.getElementById() to locate the element to hide/show.
element.style.display='' to show the element.
element.style.display='none' to hide the element.

You'll also need to establish the radiobutton status. I can't remember how you do that, but maybe there is a property called checked.

Kaled.

dkin

8:04 am on Jul 15, 2005 (gmt 0)

10+ Year Member



ok I just read your post and am very lost, not because I dont understand, but because I am terrible with javascript, I am a php coder.

So this is my small form

<form action="insert.php">
<input type="radio" name="developer"/><br>
<input type="radio" name="developer"/><br>
<input type="submit" value="submit"/>
</form>

This is the text box I would like shown if one radio is clicked.

<input type="text" name="dev1"/>

And this is the select statement I would like to be shown if the other is clicked.

<select name="dev1"><option value="Widget">Widget</option><option value="Widget 2">Widget 2</option></select>

Can someone help me put this together?

Thank you so much, Dylan

dkin

3:32 am on Jul 16, 2005 (gmt 0)

10+ Year Member



anyone?

lutherman

2:35 pm on Jul 16, 2005 (gmt 0)

10+ Year Member



howdy dkin,

maybe this is what you are lookin for...

<script language=javascript> 
function make_text(zz) {
document.getElementById(zz).innerHTML = '<select name="dev1">'+
'<option value="Widget">Widget</option><option value="Widget 2">Widget 2</option></select>';
}
function make_select(zz) {
document.getElementById(zz).innerHTML = '<input type="text" name="dev1">';
}
</script>
<form action="insert.php">
<input type="radio" name="developer" value="uniform" onClick="make_select('dd');">
<input type="radio" name="developer" value="custom" onClick="make_text('dd');">
<div id=dd></div><input type="submit" value="submit">
</form>