简体   繁体   English

多步骤表格需要某些字段到 Go 到下一步

[英]Multi-Step Form Require Certain Fields To Go to Next Step

I am trying to require certain fields before moving to the next page of fields to break up a longer form.我试图在移动到下一页字段之前要求某些字段以分解更长的表单。 In this example i just want email, not first or last to be required before moving to the next set of fields.在这个例子中,我只想要 email,而不是在移动到下一组字段之前需要第一个或最后一个。 I cannot get the error message to show that i want and have been working off of this example: Required attribute in multi step form .我无法收到错误消息以表明我想要并且一直在使用此示例: 多步骤表单中的必需属性

Thank you for any help.感谢您的任何帮助。

 function checkValue() { var name = document.getElementById("email"); if(email.value === "") { var att = document.createAttribute("required"); name.setAttributeNode(att); } }
 <form> <div class="tab">Personal Information <p><input placeholder="First name" name="first" oninput="this.className = ''"></p> <p><input placeholder="Last name" ></p> <p><input placeholder="Email" required="required" id="email" name="email" required="required" ></p> </div> <div style="overflow:auto;"> <div style="float:right;"> <button type="button" id="prevBtn">Previous</button> <button type="button" id="nextBtn" style="color:#ffffff" onclick="checkValue();" >Next</button> </div> </div> </form>

remove the type on the next button删除下一个按钮上的类型

 function checkValue() { var email = document.getElementById("email"); if(email.value === "") { var att = document.createAttribute("required"); email.setAttributeNode(att); } }
 <form> <div class="tab">Personal Information <p><input placeholder="First name" name="first" oninput="this.className = ''"></p> <p><input placeholder="Last name" ></p> <p><input placeholder="Email" id="email" name="email" ></p> </div> <div style="overflow:auto;"> <div style="float:right;"> <button type="button" id="prevBtn">Previous</button> <button id="nextBtn" style="color:#ffffff" onclick="checkValue();" >Next</button> </div> </div> </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM