/    Sign up×
Community /Pin to ProfileBookmark

JavaScript/Form troubles

I am working on putting up the Alcohol Use Disorders Identification Test for my college’s Health Services website. Problem is, my javascripting is super rusty (it’s been a couple years) and after toiling for hours I’m kind of at my wit’s end as to why this is not working.

My work so far is [URL=http://sophia.smith.edu/~jleibig/audit.html]here[/URL] .

The idea is that the score given at the bottom would indicate the level of risk of alcohol-related problems. The value attributed to each selection is the actual number that should be all added together to form a final numerical value. However it seems what my javascript computations are producing is “not a number” at all, and I don’t know why.

I would really appreciate any corrections, suggestions, or even a push in the right direction. (Maybe there’s a tutorial out there that more directly addresses what I’m trying to do?) Many thanks in advance.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisNov 14.2006 — Form fields are always strings. Javascript will generally convert strings to numbers unless you use "+" because it means "concatenate" when dealing with strings. You have to convert the form field values to numbers before adding them together. There are several ways to do this. You can use parseInt() or parseFloat(), or you can "fool" it by multiplying the value by one.
Copy linkTweet thisAlerts:
@CharlesNov 14.2006 — I prefer casting the string as a Number.
×

Success!

Help @mocha 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.25,
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,
)...