I am working on dynamic form. i have a radio button, if a user select a radio button, i want to populate a drop down menu based on the radio button values.
eg. if radio button value=value1 show drop menu of 3 items (apple, banana, mango)
eg. if radio button value=value2 show drop menu of 5 items (apple, banana, mango,apricot, ornage)
etc. I have used css to hide and show the drop down menu.
(1) the problem i am having is, this doesn't work when i insert my form in a <table></table>
; when i remove the table tags it works. its a bit strange...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function changeDiv(the_div,the_change)
{
var the_style = getStyleObject(the_div);
if (the_style != false)
{
the_style.display = the_change;
}
}
function hideAll()
{
changeDiv("main_category","none");
changeDiv("another_category","none");
changeDiv("other_category","none");
}
function getStyleObject(objectId) {
if (document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId).style;
} else if (document.all && document.all(objectId)) {
return document.all(objectId).style;
} else {
return false;
}
}
// -->
</script>
</head>
<body>
<table>
<tr>
<td align="right" valign="top">Main Category:</td>
<td>
<input type="radio" name="main_cat" onClick="hideAll(); changeDiv('main_category','block');" value="value1">value1<br />
<input type="radio" name="main_cat" onClick="hideAll(); changeDiv('main_category','block');" value="value2">value2<br />
<input type="radio" name="main_cat" onClick="hideAll(); changeDiv('main_category','block');" value="value3">value3<br />
<input type="radio" name="main_cat" onClick="hideAll(); changeDiv('main_category','block');" value="value4">value4
</td>
</tr>
<div id="main_category" style="margin-left:30px;display:none">
<tr>
<td align="right">Options:</td>
<td></td>
</tr>
</div>
<tr>
<td align="right">Aanother Category:</td>
<td>
<input type="radio" name="another_cat" onClick="hideAll(); changeDiv('another_category','block');" value="Yes">Yes
<input type="radio" name="another_cat" value="No">No
</td>
</tr>
<div id="another_category" style="margin-left:30px;display:none;">
<tr>
<td align="right">Other Category:</td>
<td>
</td>
</tr>
<tr>
<td align="right">Interest:</td>
<td>
</td>
</tr>
</div>
</table>
</body>
</html>
(2) second question is, i have a second radio buttons like this: eg. if radio button value=value1 show drop menu of 3 items (apple, banana, mango) eg. if radio button value=value2 show drop menu of 5 items (apple, banana, mango,apricot, ornage) etc. I have used css to hide and show the drop down menu.
now the trick is, if i already selected value=value1, i don't want to show value1 again in the second radio button
any help/suggestions is greatly appreciated.