Having a strange issue while trying to exit the JavaScript code.
This particular code involves an array of input elements.
Whenever the "if" statement triggers and the script should return true or false, an unexpected alert('something') pops up.
The script then carries on its execution.
Uncertain if the "..each" loop is still being executed. Any thoughts?
The objective is to break out of the .each loop and terminate the entire script.
If all checkboxes are marked as true, display the alert code located outside the ...each(function()...
<input type="checkbox" id="a" name="test[]" onclick="myfunction('a');" />
<input type="checkbox" id="b" name="test[]" onclick="myfunction('b');" />
<input type="checkbox" id="c" name="test[]" onclick="myfunction('c');" />
and this is the script snippet...
<script>
function myfunction(instuff) {
$('input[name^="test"]').each(function() {
if ($(this).prop('checked') == false) {
//...execute code...
return true; //return false; has similar behavior.
}
})
//...execute additional code...
alert('something');
}
</script>