简体   繁体   English

如何将单选按钮值从表单发送到电子邮件

[英]How to send radio button value from form to email

 <script> var currentTab = 0; // Current tab is set to be the first tab (0) showTab(currentTab); // Display the crurrent tab function showTab(n) { // This function will display the specified tab of the form... var x = document.getElementsByClassName("tab"); x[n].style.display = "block"; //... and fix the Previous/Next buttons: if (n == 0) { document.getElementById("prevBtn").style.display = "none"; } else { document.getElementById("prevBtn").style.display = "inline"; } if (n == (x.length - 1)) { document.getElementById("nextBtn").innerHTML = "Submit"; } else { document.getElementById("nextBtn").innerHTML = "Next"; } //... and run a function that will display the correct step indicator: fixStepIndicator(n) } function nextPrev(n) { // This function will figure out which tab to display var x = document.getElementsByClassName("tab"); // Exit the function if any field in the current tab is invalid: if (n == 1 && !validateForm()) return false; // Hide the current tab: x[currentTab].style.display = "none"; // Increase or decrease the current tab by 1: currentTab = currentTab + n; // if you have reached the end of the form... if (currentTab >= x.length) { // ... the form gets submitted: document.getElementById("regForm").submit(); return false; } // Otherwise, display the correct tab: showTab(currentTab); } function validateForm() { // This function deals with validation of the form fields var x, y, i, valid = true; x = document.getElementsByClassName("tab"); y = x[currentTab].getElementsByTagName("input"); // A loop that checks every input field in the current tab: for (i = 0; i < y.length; i++) { // If a field is empty... if (y[i].value == "") { // add an "invalid" class to the field: y[i].className += " invalid"; // and set the current valid status to false valid = false; } } // If the valid status is true, mark the step as finished and valid: if (valid) { document.getElementsByClassName("step")[currentTab].className += " finish"; } return valid; // return the valid status } function fixStepIndicator(n) { // This function removes the "active" class of all steps... var i, x = document.getElementsByClassName("step"); for (i = 0; i < x.length; i++) { x[i].className = x[i].className.replace(" active", ""); } //... and adds the "active" class on the current step: x[n].className += " active"; } </script> 
 <div class="tab"><h4>Zip Code</h4> <p><input type="text" class="text1" placeholder="Enter zip code..." oninput="this.className = ''" name="zipcode"></p> </div> <div class="tab"><h4>How long have you been planning to sell your property?</h4> <p><input type="radio" name="rdb" value="1-3 months" class="option-input radio" checked/> 1-3 months</p> <p><input type="radio" name="rdb" value="4-6 months" class="option-input radio"> 4-6 months</p> <p><input type="radio" name="rdb" value="more than 6 months" class="option-input radio"> more than 6 months</p> </div> <div class="tab"><h4>Type of property?</h4> <p><input type="radio" name="rdb1" value="Single Family House" class="option-input radio" checked/> Single Family House</p> <p><input type="radio" name="rdb1" value="Condo" class="option-input radio"> condo</p> <p><input type="radio" name="rdb1" value="Mobile" class="option-input radio">Mobile</p> <p><input type="radio" name="rdb1" value="Townhouse" class="option-input radio">Townhouse</p> <p><input type="radio" name="rdb1" value="Multi-units" class="option-input radio">Multi-units</p> </div> 

I do not receive radio button value in an email. 我没有在电子邮件中收到单选按钮值。 all other text box, email and phone is shown by run this above code but the main issue is there with radio button. 运行上述代码即可显示所有其他文本框,电子邮件和电话,但主要问题是单选按钮。

If i comment the radio tags then the code runs perfectly, with radio i received only email without any data. 如果我评论单选标签,则代码可以完美运行,单选我仅收到电子邮件,没有任何数据。 also please check the value of radio button, is it contain space between two words is yes then how it works? 还请检查单选按钮的值,它是否包含两个单词之间的空格,是的,它如何工作?

Get the radio button value 获取单选按钮值

var rdb = document.getElementsByName('rdb').value;

or 要么

document.querySelector('input[name="rdb"]:checked').value

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

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