0
I am using the following code to check if a radio is selected, if you are, to perform such a function:
<script language="javascript">
document.onclick = function setFries() {
var apc = document.getElementById("10000_3").checked;
var ape = document.getElementById("10000_5").checked;
if (apc) {
window.alert("teste 1");
}
}
</script>
But if I add more than 2 variables the script simply doesn’t work.
In total I will use 24 variables, so I did it as follows:
<script language="javascript">
document.onclick = function setFries() {
var apc = document.getElementById("10000_3").checked;
var ape = document.getElementById("10000_5").checked;
var aac = document.getElementById("10000_6").checked;
var aae = document.getElementById("10000_7").checked;
var cpc = document.getElementById("10000_8").checked;
var cpe = document.getElementById("10000_9").checked;
var cac = document.getElementById("10000_10").checked;
var cae = document.getElementById("10000_11").checked;
var dpc = document.getElementById("10000_12").checked;
var dpe = document.getElementById("10000_13").checked;
var dac = document.getElementById("10000_14").checked;
var dae = document.getElementById("10000_15").checked;
var hpc = document.getElementById("10000_16").checked;
var hpe = document.getElementById("10000_17").checked;
var hac = document.getElementById("10000_18").checked;
var hae = document.getElementById("10000_19").checked;
var lpc = document.getElementById("10000_20").checked;
var lpe = document.getElementById("10000_21").checked;
var lac = document.getElementById("10000_22").checked;
var lae = document.getElementById("10000_23").checked;
var ppc = document.getElementById("10000_24").checked;
var ppe = document.getElementById("10000_25").checked;
var pac = document.getElementById("10000_26").checked;
var pae = document.getElementById("10000_27").checked;
if (apc) {
window.alert("teste 2");
}
}
</script>
But it didn’t work, I was excluded 1 in 1 variable, and it only worked when I was 2.
Please, where is the error?
Do these HTML elements exist? Can you explain what you are trying to do? Writing all this by hand seems a bad idea... I think you can optimize a lot.
– Sergio
Where does the A3 variable come from in the first code snippet? How about running the setFries function inside the click event.
– Maurivan
Wesley, as @Sergio pointed out, it seems to me that you had a lot of effort to do something simple, take a look at the following fiddle.: Jsfiddle
– Tobias Mesquita
@Maurivan thanks for the remark, I forgot to change it on how much I wrote the question here on the site, would be 'apc'
– Wesley
@Sergio thanks for the remark, I was working with nonexistent references, I’m readjusting to see if the problem was just this.
– Wesley
@Can Tobias please move to a chat? I don’t know if I should be commenting or editing the question. ps: don’t know how to move to a chat
– Wesley
@Wesley you still haven’t explained what you want to do...
– Sergio
@Sergio olá Sergio, I went to Fiddle to illustrate my need https://jsfiddle.net/h3hkduym/6/ There are 12 forms on the same page, each of them have 2 radio input to choose either option. The function called by onclick on the Submit button should display an alert for the user (according to the selection will be a different Alert). What I couldn’t do: Have the function clear the user selection in the other forms, as each one has 2 selection options and 1 Submit button. Example, form 1, selected 1st radio, when submitting reset other selections.
– Wesley
@Tobiasmesquita Tobias, is it possible to modify your code so that when you click on a radio, the others are deselected? https://jsfiddle.net/6dkenu99/4/ as I did, it is not possible to choose the radios of form 2 or 3.
– Wesley