I have a quiz that contains a form that uses radio buttons and values. There is a bit in the js code, on the 18th line or so, that should provide for an alert when some of the questions are not answered. It doesn’t seem to be working and I don’t know why. The alert is the only part of the code not working, everything else is fine.
[code=php]<script language=”Javascript”>
function getVal( radiob ){
var val = 0;
for( i=0; i < radiob.length; i++ ){
if( radiob[i].checked ){
val = parseInt(radiob[i].value);
if(val == ‘NaN’) val = 0;
}
}
return val;
}
function doSum( formName ){
//add results from q1 through q2
var sum = 0;
var err = 0;
var msg = “Please answer all the questions.n”;
var temp;
temp = getVal( formName.q1 );
if( temp )
sum += temp;
else
err = 1;
temp = getVal( formName.q2 );
if( temp )
sum += temp;
else
err = 1;
temp = getVal( formName.q3 );
if( temp )
sum += temp;
else
err = 1;
temp = getVal( formName.q4 );
if( temp )
sum += temp;
else
err = 1;
temp = getVal( formName.q5 );
if( temp )
sum += temp;
else
err = 1;
//if( err ) alert( msg );
//else
window.location = “./results.shtml?” + sum;
}
</script>
The page is posted at: [url]http://www.get-net-results.com/web/story_net_fit.html
Thanks for any suggestions.