The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

Reply to this topicStart new topic
> Simple multiple row sum calculator, Halp : )
post Mar 15 2020, 01:29 AM
Post #1

Group: Members
Posts: 3
Joined: 3-March 20
Member No.: 27,217

Hello. I am new to all programming, and taking some basics course atm.

So here is the problem that I have now:

When the user click the button, it should print the sum of all the boxes.
I am not sure what I've done wrong with this code and a little help would be appreciated!

<!DOCTYPE html>
<meta charset="UTF-8"/>
<title>Ostorkori 🛒</title>
Tuote 1: <input id="tuote_1"/>
Tuote 2: <input id="tuote_2"/>
Tuote 3: <input id="tuote_3"/>
Tuote 4: <input id="tuote_4"/>
Tuote 5: <input id="tuote_5"/>
Tuote 6: <input id="tuote_6"/>
<button type="button" onclick="hintaYht();">Yhteensä</button>
<div id="tulosX">

function hintaYht(){
var tuote1 = Number(document.getElementById(tuote_1).value);
var tuote2 = Number(document.getElementById(tuote_2).value);
var tuote3 = Number(document.getElementById(tuote_3).value);
var tuote4 = Number(document.getElementById(tuote_4).value);
var tuote5 = Number(document.getElementById(tuote_5).value);
var tuote6 = Number(document.getElementById(tuote_6).value);

var tulos = tuote1 + tuote2 + tuote3 + tuote4 + tuote5 + tuote6;
var x = document.createElement("tulos");
var t = document.createTextNode("This is a span element.");

document.getElementById("tulosX").innerHTML = tulos;


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Mar 15 2020, 04:38 PM
Post #2


Group: WDG Moderators
Posts: 8,435
Joined: 10-August 06
Member No.: 7


The ID value must be quoted:

(unless it's a variable, but that's not the case here).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


- Lo-Fi Version Time is now: 1st June 2020 - 01:08 AM