# JS calculation

• 03-08-2014, 07:44 AM
ieyza
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;
}
• 03-08-2014, 08:40 AM
JMRKER
What does your HTML look like?
What does the error console say?

Try not to double post.
• 03-09-2014, 07:51 AM
ieyza
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 :)
• 03-09-2014, 09:59 AM
JMRKER
Quote:

Originally Posted by JMRKER
What does your HTML look like?
What does the error console say?

Try not to double post.

Quote:

Originally Posted by ieyza
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 :)

Since you did not answer the 1st post questions :rolleyes:,
the following is a simulation of your problem without the HTML elements.

Code:

```<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title> Untitled </title> </head> <body> <script type="text/javascript"> 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(); } </script> </body> </html>```
• 03-09-2014, 11:48 AM
Kevin2
Or possibly??

Code:

```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= 1*a+1*b+1*c;        // The "1*" forces the math rather than concatenating values   document.forms[0].jumbyrkerusi.value =s; }```
• 03-09-2014, 07:16 PM
JMRKER
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.
• 03-10-2014, 12:15 AM
ieyza
thnx Kevin2.. it really works.. thnk you very much for ur help :D
• 03-10-2014, 08:50 AM
tech_soul8
Quote:

Originally Posted by ieyza
thnx Kevin2.. it really works.. thnk you very much for ur help :D

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

Quote:

If there are spaces it might not be converting correctly. That information has never been supplied.
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.

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.15254 seconds
• Memory Usage 2,365KB
• Queries Executed 11 (?)
Template Usage (21):
• (2)bbcode_code_printable
• (4)bbcode_quote_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• bbcode_parse_complete_precache
• bbcode_parse_complete
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates