动态 html 表单
我正在研究动态形式。 我有一个单选按钮,如果用户选择一个单选按钮,我想根据单选按钮值填充一个下拉菜单。
例如。如果单选按钮 value=value1 显示 3 个项目(苹果、香蕉、芒果)的下拉菜单,
例如。如果单选按钮 value=value2 显示 5 个项目的下拉菜单(苹果、香蕉、芒果、杏子、ornage)
等。我使用 css 来隐藏和显示下拉菜单。
(1)我遇到的问题是,当我将表单插入
时,这不起作用;当我删除表格标签时它就起作用了。这有点奇怪......
<!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)第二个问题是,我有第二个单选按钮,如下所示: 例如。如果单选按钮 value=value1 显示 3 个项目的下拉菜单(苹果、香蕉、芒果) 例如。如果单选按钮 value=value2 显示 5 个项目的下拉菜单(苹果、香蕉、芒果、杏子、ornage)等。我使用 css 来隐藏和显示下拉菜单。
现在的技巧是,如果我已经选择了 value=value1,我不想在第二个单选按钮中再次显示 value1,
非常感谢任何帮助/建议。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
try this
我建议看一些 Javascript 框架,这会让你的生活变得更轻松。看看 ExtJS: http://www.sencha.com/products/js/ 或 jQuery:http://jquery.com/ 这些框架可以轻松处理您的问题。
I would suggest taking a look at some Javascript frameworks which will make your life a lot easier. Take a look at ExtJS: http://www.sencha.com/products/js/ or jQuery: http://jquery.com/ these frameworks can handle your problems with ease.