/    Sign up×
Community /Pin to ProfileBookmark

script problems… please help

this is kinda the same as a previous post, but with a twist. I have 6 sets of radios that i’m trying to do some simple operations with. My problem lies in having total take on a value, and also the only radio values that are summed are only the selected ones, and someone try this out to see where the problem exists.

<html>

<head>

<script>

function addValues ()
{

var first = second = total = i = 0;

var f = document.form_new;
var x = 1;
var elem;

for(i=1;i < 4; i++)
{
elem = f.elements[“e”+x];
if ( elem.checked )
{
first += parseInt( elem.value, 10 );
}
x++;
}

x = 1;
for(i=1;i < 4; i++)
{ elem = f.elements[“f”+x];
if ( elem.checked )
{
second += parseInt( elem.value, 10 );
}
x++;
}

total = ( first >= second ) ? first : second;

document.write (total)
}

</script>

</head>

<body>

<form name=”form_new”>
<p>English</p>
<p>e1<input type=”radio” value=”10″ name=”e1″>e2<input type=”radio” name=”e2″ value=”10″>e3<input type=”radio” name=”e3″ value=”10″></p>
<p>e1<input type=”radio” name=”e1″ value=”5″>e2<input type=”radio” value=”5″ name=”e2″>e3<input type=”radio” name=”e3″ value=”5″></p>
<p>e1<input type=”radio” name=”e1″ value=”1″>e2<input type=”radio” name=”e2″ value=”1″>e3<input type=”radio” value=”1″ name=”e3″></p>
<p>French</p>
<p>f1<input type=”radio” value=”10″ name=”f1″>f2<input type=”radio” name=”f2″ value=”10″>f3<input type=”radio” name=”f3″ value=”10″></p>
<p>f1<input type=”radio” name=”f1″ value=”5″>f2<input type=”radio” value=”5″ name=”f2″>f3<input type=”radio” name=”f3″ value=”5″></p>
<p>f1<input type=”radio” name=”f1″ value=”1″>f2<input type=”radio” name=”f2″ value=”1″>f3<input type=”radio” value=”1″ name=”f3″></p>
<p><input type=”Submit” value=”get value” onclick=”addValues();”><input type=”reset” value=”Clear” name=”Reset”></p>
</form>

</body>

</html>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @catchup 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.15,
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,
)...