You are declaring the “myVal2” variable inside the if block, so that’s the only place it’s available. If you want the variable to be available outside of the if block, you need to declare it (with a var statement) OUTSIDE of the block – and make sure that you don’t use a var statement inside the block for a variable with the same name.
var statusCheck = document.forms[0].statusCheck.value;
var docStatusValue;
for (var i=0; i < document.forms[0].docStatus.length; i++) {
That leaves you with a docStatusValue variable that is either null or that contains a value gathered from the checked radio button. If you use a var statement inside the loop:
var statusCheck = document.forms[0].statusCheck.value;
var docStatusValue;
for (var i=0; i < document.forms[0].docStatus.length; i++) {
if (document.forms[0].docStatus[i].checked) {
var docStatusValue = document.forms[0].docStatus[i].value;
}
}
then the docStatusValue variable outside the loop will always be null because the docStatusValue variable inside the loop is a different variable.