/    Sign up×
Community /Pin to ProfileBookmark

radio validation not working

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>[/code]

The page is posted at: [url]http://www.get-net-results.com/web/story_net_fit.html[/url]
Thanks for any suggestions.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@woodknutDec 22.2003 — SWAG:

I wonder if the variable 'err' is actually storing a numeric value (i.e. 1 or 0) that isn't being checked properly?

What happens if you change it to true/false?

I have seen scripts get "confused" when you use different formatting. I'd also suggest making the last test look just like the others; I know how "whitespace" is supposed to be seen by the parser but who knows?

if( err )

alert();

else

window.yada

W.
Copy linkTweet thisAlerts:
@beachshoozauthorDec 23.2003 — It worked!!! The second idea. I took out the // in front of the if's and else's and it worked. I thank you, my client thanks you!

BS
Copy linkTweet thisAlerts:
@woodknutDec 23.2003 — Client?! CLIENT?!

We're doing this for money?

Cool!

? ?

BTW Those // are how you create a comment and the text behind them are not seen by the parser. I though you put them there to identify the suspect code. Also notice the line:

"//add results from q1 through q2" ?
Copy linkTweet thisAlerts:
@beachshoozauthorDec 23.2003 — Well, it ain't much but a girl's gotta make a living. As penance, I will spend a couple hours helping solve some html problems in the General Forum...?

Thanks for all of your help. This web site is a wonderful.
×

Success!

Help @beachshooz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...