我有一组问题在html的形式
I have a set of Questions in a html form
我在html表单中有一组问题。其中一些问题的答案在单选按钮中显示,一些问题的答案通过复选框显示。
问题是我想数一下答案。我有5个问题。其中3个是"是"或"否"问题(单选按钮)。其中2个是选择题(复选框)。用户回答了5个问题中的4个。我的计数器会显示4然后只有提交按钮是可点击的。
<form method="post" action="" id="myForm">
<p>Name:<br>
<input type="text" name="Lname" size="50" onKeyPress="return lettersonly(event)" id="lname" value=""required/>
</p>
<p>E-mail:<br>
<input type="text" name="Lemail" size="50" onKeyPress="return emailLetters(event)" value=""required/>
</p>
<p>Gender:
<input type="radio" name="Lgender" value="female" required>Female
<input type="radio" name="Lgender" value="male" required>Male
</p>
<p>1. What is your special interests? <i><small>you can choose more than one option</small></i><br>
<input type="checkbox" name="q01[]" value="Circuit Design">Circuit Design<br>
<input type="checkbox" name="q01[]" value="System Design">System Design<br>
<input type="checkbox" name="q01[]" value="Logical Circuits">Logical Circuits<br>
<input type="checkbox" name="q01[]" value="IT-Security">IT-Security<br>
<input type="checkbox" name="q01[]" value="Embedded System">Embedded System<br>
<input type="checkbox" name="q01[]" value="Others">Others<br>
</p>
<p>2. Have you taught Logic Circuits or other related Subjects to undergraduate students? <br>
<input type="radio" name="q02" value="Yes" onclick="display(this)" required>Yes
<input type="radio" name="q02" value="No" onclick="display(this)" required>No
</p>
<div id="hideform" style="display:none">
<p>3. Have you taught VERILOG or other types of Gate Level programming languages to undergraduate students? <br>
<input type="radio" name="q03" value="Yes">Yes
<input type="radio" name="q03" value="No">No
</p>
<p>4. In your opinion, how many of students have some difficulties to cope with the concept of complex combination of Logic Units and implementation of them by a programming language like VERILOG or VHDL? <br>
<input type="checkbox" name="q04" value="None of the Students">None of the Students<br>
<input type="checkbox" name="q04" value="Small Group of Students">Small Group of Students<br>
<input type="checkbox" name="q04" value="Half of the Students">Half of the Students<br>
<input type="checkbox" name="q04" value="Majority of the Students">Majority of the Students<br>
</p>
<p>5. Do you have enough time to give them enough examples during the face to face classroom? <br>
<input type="radio" name="q05" value="Yes">Yes
<input type="radio" name="q05" value="No">No
</p>
<p><input class= "submitbtn" type="submit" name="submit" value="Submit" onclick="myFunction()"></p>
<!--onclick= "alert('Thanks for your time!')"-->
</form>
您将需要jquery (https://code.jquery.com/)来轻松完成此操作。此外,将disabled
添加到提交按钮中,使其不可点击。然后添加自己的JavaScript代码:
$(document).ready(function(){
//check form when page is loaded
checkform();
//check form when element is clicked
$("input[type='radio'][name^='q'],input[type='checkbox'][name^='q']").click(function(){
checkform();
});
});
function checkform(){
counter =0;
// Count filled form sections
for(i=1;i<=5;i++){
if($('input[name="q0'+i+'"],input[name="q0'+i+'[]"]').is(':checked')){
counter++;
}
}
// submit form
if(counter>=4){
//enable button
$(".submitbtn").show(); //better use an id for the button
}
}
确保没有其他以"q"开头的输入元素,否则在您的页面上我建议的代码将无法工作。
相关文章:
- 使用Handontable在同一列中用纯文本和html对问题进行排序
- 在HTML中调用函数时出现问题
- 在将javascript附加到我的html中时遇到问题
- 使用ajax在html中加载html文件时出现的问题
- 将HTML表单发布到iframe会导致浏览器历史记录出现问题
- 使用HTML和JS的iPhone游戏中的性能问题,以及appMobi
- Html、css和jQuery.我的代码有问题
- jQuery-数据提取问题(html遍历)
- ajax html javascript页面刷新无闪烁问题
- html单选按钮检查问题
- c# mvc nreco HtmlToPdfConverter 问题将 html 文档转换为 pdf
- CSS 溢出的滚动问题:滚动 HTML
- 在我的Javascript和HTML之间的表单提交按钮链接中遇到问题
- Ckeditor出现格式错误的html问题
- 重定向至“索引.html问题”诊断树
- 嵌入在 HTML 问题中的 Rails 标签
- 特定的javascript/html问题
- 用ajax/javascript将文本文件中的数据加载到html问题中
- Jquery还是HTML问题?为什么不是'我的选择器不工作
- 博客HTML问题与JSC_Parse_Error