<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>
&#13;
<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>
&#13;
我在电子邮件中没有收到单选按钮值。通过运行上面的代码显示所有其他文本框,电子邮件和电话,但主要问题是单选按钮。
如果我评论无线电标签,那么代码运行完美,无线电我只收到没有任何数据的电子邮件。还请检查单选按钮的值,它是否包含两个单词之间的空格是,然后它是如何工作的?
答案 0 :(得分:0)
获取单选按钮值
var rdb = document.getElementsByName('rdb').value;
或
document.querySelector('input[name="rdb"]:checked').value