UPDATE:很抱歉,在从perl脚本中删除语法时,我删除了太多。这是迄今为止的代码。我将"student_name"发布到script.pl。这可以在文本表单中输入,也可以从下拉框中选择,您可以使用单选按钮进行选择。但它似乎对我不起作用。
<form method="post" action="script.pl">
Type Student Name<input type="radio" name="student_name"><input type=text name="student_name" size=50>
<b>OR</b>
Select Student Name<input type="radio" name="student_name">
<select name="student_name">
<option value="jack">Jack</option>
</select>
</form>
旧职位----------------------------------------------------------------------------------------------------------------我正在尝试创建一个表单,用户可以选中第一个单选按钮并自己输入名称,也可以选中第二个按钮并从下拉列表中选择一个值并传递。由于某些原因,我无法使其正常工作,值没有通过。我希望在单选按钮后输入或选择的任何值都能发布。
输入名称()_______或()(下拉框)
<td width=30% bgcolor=#CEDBE7>Student Name</td>
<td bgcolor=#CEDBE7 width=70%>
<input type=radio name=student_name value=><input type=text name=student_name size=50>
<b>OR</b>
<input type=radio name=student_name>
<select>
<option value=drop1>drop down option 1</option>
</select>
我想你是指这个
window.onload=function() { // when the page has loaded
var rads = document.querySelectorAll('input[name="student_rad"]'); // get all radios with name student_rad
for (var i=0;i<rads.length;i++) {
rads[i].onclick=function() { // assign onclick to each
if (this.id=="inp") { // the one deciding input
document.getElementById("stud_sel").selectedIndex=0; // reset select
document.getElementById("student_name").focus();
}
}
}
document.getElementById("stud_sel").onchange=function() { // when selecting
document.getElementById("sel").click(); // click the rad to select it
document.getElementById("student_name").value=this.value;
}
var rad = document.querySelector('input[name="student_rad"][checked]');
if (rad == null) {
document.getElementById("inp").click(); // check default
}
}
<td width=30% bgcolor=#CEDBE7>Student Name</td>
<td bgcolor=#CEDBE7 width=70%>
<input type="radio" name="student_rad" id="inp"/><input type="text" name="student_name" id="student_name" size=50 />
<b>OR</b>
<input type="radio" name="student_rad" id="sel" />
<select id="stud_sel">
<option value="">Please select</option>
<option value="Frank">Frank</option>
</select>
您的select标记没有name属性。提交表单时,传递的值由元素名称标识。
除此之外,您的HTML看起来像是10年前写的。使用CSS为元素设置样式,只对真实的表使用table标记,而不用于创建元素布局,将属性值放在引号下。