插入复选框的值而不提交

insert value of check boxes without submitting

本文关键字:提交 复选框 插入      更新时间:2023-09-26

这是一个选择类和节的表单。当选择一个类时,将出现四个部分。我真的需要知道如何从这些复选框中获取输入,并确定哪个部分属于哪个类。如有需要,也请提供此代码的任何修改。谢谢你

无标题的文档

<script type="text/javascript"> 
function showMe (it, box) { 
var vis = (box.checked) ? "block" : "none"; 
document.getElementById(it).style.display = vis; 
} 
function showMe2 (it) { 
var vis = document.getElementById(it).style.display 
if (vis == "block") { document.getElementById(it).style.display = "none"; } 
else { document.getElementById(it).style.display = "block"; } 
} 
</script>
<style type="text/css">
.divstyle
{
display: none;
border: 1px solid #000;
height: 100px;
width: 200px;
}
</style>
</head>
<body>
<table>
<tr>
<td><input name="class[one]" type="checkbox" onclick="showMe('div1', this)" /> 
One</td>
</tr>
<tr>
<td><input name="class[two]" type="checkbox" onclick="showMe('div1', this)" />
Two</td>
</tr>
<tr>
<td><input name="class[three]" type="checkbox" onclick="showMe('div1', this)" />
Three</td>
</tr>
<tr>
<td><input name="class[four]" type="checkbox" onclick="showMe('div1', this)" />
Four</td>
</tr>
<tr>
<td><input name="class[five]" type="checkbox" onclick="showMe('div1', this)" /> 
Five
</td>
</tr>
<tr>
<td><input name="class[six]" type="checkbox" onclick="showMe('div1', this)" />
Six
</td>
</tr>
<tr>
<td><input name="class[seven]" type="checkbox" onclick="showMe('div1', this)" />
Seven</td>
</tr>
<tr>
<td><input name="class[eight]" type="checkbox" onclick="showMe('div1', this)" />
Eight</td>
</tr>
<tr>
<td><input name="class[nine]" type="checkbox" onclick="showMe('div1', this)" />
Nine</td>
</tr>
<tr>
<td><input name="class[ten]" type="checkbox" onclick="showMe('div1', this)" />
Ten</td>
</tr>
</table>
<div class="divstyle" id="div1">
<table>
<td><input name="sec[a]" type="checkbox" value="" />a</td>
<td><input name="sec[b]" type="checkbox" value="" />b</td>
<td><input name="sec[c]" type="checkbox" value="" />c</td>
<td><input name="sec[d]" type="checkbox" value="" />d</td>
</table>
</div>
</body>
</html>

您可以在复选框中设置ID,并将其传递给您的函数。

<td><input id="ten" name="class[ten]" type="checkbox" onclick="showMe('div1', this)" />
Ten</td>
showMe函数

document.getElementById('checked_box').value = box.id;

将值发送到一个隐藏字段

<input type="hidden" name="checked_box" id="checked_box" value="" />

不太确定你最终想要完成什么,但这是一个开始。