Click to See Complete Forum and Search --> : Radio Button selection changes Menu pulldown


ivcp
10-08-2003, 08:52 PM
I like to know how to do with java script :
I have radio buttons and depending on which radio button is clicked I want to show a drop down box with value

Thanks

pyro
10-08-2003, 09:40 PM
Try playing around with this, and see if you can use it to do what you need:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
function add(index,txt,val) {
opt = document.createElement("option");
document.myform.myselect.options.add(opt, index);
opt.text = txt;
opt.value = val;
}
function remove(index) {
document.myform.myselect.options[index] = null;
document.myform.myselect.selectedIndex = 0;
}
</script>
</head>
<body>
<p><a href="#" onclick="add('1','AddedText','AddedValue'); return false;">add</a> | <a href="#" onclick="remove('0'); return false;">remove</a></p>
<form name="myform" action="">
<p><select name="myselect">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
</select></p>
</form>
</body>
</html>Here's how the add and remove functions are used:

add('the index in the <select> tag','the text for the new option','the value for the new option')

remove('the index in the <select> tag')

The index works numerically. 0 is the first option, 1 is the second, and so forth (it's like any other array).