/    Sign up×
Community /Pin to ProfileBookmark

JS calculation

i am now developing a wed-based system involving JS calculation which is ADD operator in form.
but i still can’t figure this out

function jumkerusi()
{

var a = parseInt(document.forms[0].jumbyrsofa.value);
var b = parseInt(document.forms[0].jumbyrvip.value);
var c = parseInt(document.forms[0].jumbyrplastik.value);
var s = parseInt(document.forms[0].jumbyrkerusi.value);

s= a+b+c;

document.forms[0].jumbyrkerusi.value =s;
}

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERMar 08.2014 — What does your HTML look like?

What does the error console say?

Try not to double post.
Copy linkTweet thisAlerts:
@ieyzaauthorMar 09.2014 — var a, b and c containing 3 integers which to be sum up using ADD operator and the answer would be in var s.. for example when 1+2+3 turns out to be 123 instead equal to 6. sorry i know it's kinda basic but im still learning this.. tq for ur reply ?
Copy linkTweet thisAlerts:
@JMRKERMar 09.2014 — What does your HTML look like?

What does the error console say?

Try not to double post.[/QUOTE]


var a, b and c containing 3 integers which to be sum up using ADD operator and the answer would be in var s.. for example when 1+2+3 turns out to be 123 instead equal to 6. sorry i know it's kinda basic but im still learning this.. tq for ur reply ?[/QUOTE]

Since you did not answer the 1st post questions :rolleyes:,

the following is a simulation of your problem without the HTML elements.

<i>
</i>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="UTF-8" /&gt;

&lt;title&gt; Untitled &lt;/title&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;script type="text/javascript"&gt;
function jumkerusi() {
var sa = '1', sb = '2', sc = '3', ss = '';
var a = parseInt(sa);
var b = parseInt(sb);
var c = parseInt(sc);
// var s = parseInt(ss);
var s= a+b+c;
alert('With parseInt: '+s);
}
function jumkerusiWithoutParseInt() {
var sa = '1', sb = '2', sc = '3', ss = '';
var a = sa;
var b = sb;
var c = sc;
var s= a+b+c;
alert('Without parseInt: '+s);
}

window.onload = function() {
jumkerusiWithoutParseInt();
jumkerusi();
}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@Kevin2Mar 09.2014 — Or possibly??

function jumkerusi(){
var a = parseInt(document.forms[0].jumbyrsofa.value);
var b = parseInt(document.forms[0].jumbyrvip.value);
var c = parseInt(document.forms[0].jumbyrplastik.value);
var s = parseInt(document.forms[0].jumbyrkerusi.value);
s= [B][COLOR="#FF0000"]1*[/COLOR][/B]a+[B][COLOR="#FF0000"]1*[/COLOR][/B]b+[B][COLOR="#FF0000"]1*[/COLOR][/B]c; // The "1*" forces the math rather than concatenating values
document.forms[0].jumbyrkerusi.value =s;
}
Copy linkTweet thisAlerts:
@JMRKERMar 10.2014 — That's fine, multiplying by 1, but that is the purpose of what the parseInt function does, so it is not needed.

The problem in the original post *may* be related to the HTML entry value.


If there are spaces it might not be converting correctly. That information has never been supplied.
Copy linkTweet thisAlerts:
@ieyzaauthorMar 10.2014 — thnx Kevin2.. it really works.. thnk you very much for ur help ?
Copy linkTweet thisAlerts:
@tech_soul8Mar 10.2014 — thnx Kevin2.. it really works.. thnk you very much for ur help ?[/QUOTE]

It works now but the big question is will it work some other time? For example:

If there are spaces it might not be converting correctly. That information has never been supplied.[/quote]

You're not paying attention to what other forum members asked you about! So this may be just temporary solution until the next time when you come back with the same kind of problem.
×

Success!

Help @ieyza 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.19,
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,
)...