Отсюда я получил форму https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_form_steps
что я пытаюсь сделать
Я добавил эти две вкладки
<div class="tab">
<input type="radio" name="question1" oninput="this.className = ''" value="answer1">
<input type="radio" name="question1" oninput="this.className = ''" value="answer2">
</div>
<div class="tab">
<input type="radio" name="question2" oninput="this.className = ''" value="answer1">
<input type="radio" name="question2" oninput="this.className = ''" value="answer2">
</div>
и в коде javascript в "function validateform" Вместо этого
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
}
я отредактировал и вставил javascript, как показано ниже:
y = x[currentTab].getElementsByName("question");
и
for (i = 0; i < y.length; i++) {
// If a field is empty...
if (y[i].checked == false) {
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false
valid = false;
}
}
И это не сработает.
пожалуйста, ребята, вы можете мне помочь?