I’m a novice at Jquery/Javascript programming so please be gentle 😉
The function below checkes if a radiobutton from a specific group is selected. However I can’t get the:
var checkifonechecked = true;
to be passed to the if statement. It returns a Uncaught ReferenceError: checkifonechecked is not defined. How can I pass this var?
function stap3() {
$('input[name=ostap2]').each(function() {
if (this.checked) {
var checkifonechecked = true;
}
});
if(checkifonechecked){
$('#stap1, #stap2, #stap4, #stap5, #stap6, #stap7').hide();
$('#stap3').show();
} else {
alert('neen'); }
}
Many thanx for any assistance,
Your problem is because you are declaring your
checkifonecheckedvariable inside an anonymous function (AKA a lambda). Once the anonymous function has ended, the variable no longer exists, so attempting to use it in thestap3function will fail with an “Uncaught ReferenceError” as you describe.You need to declare your variable somewhere it’s guaranteed to execute (e.g. the beginning of your
stap3function), like so: