Answer the question
In order to leave comments, you need to log in
2 scripts not working together?
Good evening, there are two scripts, they work fine separately, but together the script for outputting to a paragraph does not work, please help, I can’t fix it myself, the forms should work together on one page, here is the code:
<form>
<input type="checkbox" onclick="checker()">
<label for="ddr3200">DDR4-3200</label> <br>
<input type="checkbox" onclick="checker()">
<label for="ddr2933">DDR4-2933</label> <br>
<input type="checkbox" onclick="checker()">
<label for="ddr2666">DDR4-2666</label>
</form>
let form = document.forms[0];
form.onsubmit = checker;
function checker() {
let array = [...form.querySelectorAll(":checked")],
s;
if (array.length)
s = "Вы выбрали память: " + array.map(e => e.nextElementSibling.textContent).join(', ');
else
s = "Память не выбрана";
alert(s);
return false;
}
<form>
<input type="checkbox" onclick="chatcheck()" id="elem3">
<label for="ddr3200">DDR4-3200</label> <br>
<input type="checkbox" onclick="chatcheck()" id="elem4">
<label for="ddr2933">DDR4-2933</label> <br>
<input type="checkbox" onclick="chatcheck()" id="elem5">
<label for="ddr2666">DDR4-2666</label>
<p class="abzac2"></p>
</form>
let formText = document.forms[0];
formText.onsubmit = chatcheck;
let abzac2 = document.querySelector('.abzac2');
function chatcheck() {
let array = [...formText.querySelectorAll(":checked")],
s;
if (array.length)
s = "Вы выбрали память: " + array.map(e => e.nextElementSibling.textContent).join(', ');
else
s = "Память не выбрана";
abzac2.innerHTML = s;
return false;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question