I have the following code in HTML:
<input type="checkbox" id="Pacote_i" name="Pacote" value="Pacote i" onClick="soma()">
<input type="checkbox" id="Pacote_ii" name="Pacote" value="Pacote ii" onClick="soma()">
<input type="checkbox" id="Pacote_iii" name="Pacote" value="Pacote iii" onClick ="soma()">
I need to get the values of these fields and create their respective variables. I'm trying the code below in Javascript, but I'm not getting it. See:
var pacote = document.getElementsByName('Pacote');
for (var i = 0; i < pacote.length; i++){
if ( pacote[i].checked ) {
if(pacote[i].value == "Pacote i"){
var Pacote_i = "Pacote UM";
alert(Pacote_i);
}else if (pacote[i].value == "Pacote ii") {
var Pacote_ii = "Pacote DOIS";
alert(Pacote_ii);
}else if (pacote[i].value == "Pacote iii") {
var Pacote_iii = "Pacote TRÊS";
alert(Pacote_iii);
}
}
}
Is the above code correct?
Thank you!