Click here to Skip to main content
15,891,423 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionRe: get a function to countdown (from any number) to zero Pin
Richard MacCutchan25-Dec-18 21:18
mveRichard MacCutchan25-Dec-18 21:18 
AnswerRe: get a function to countdown (from any number) to zero Pin
Bohdan Stupak9-Jan-19 19:40
professionalBohdan Stupak9-Jan-19 19:40 
Questionhow to get a js fuction to return html opening and closing tag Pin
Member 1409810522-Dec-18 17:34
Member 1409810522-Dec-18 17:34 
AnswerRe: how to get a js fuction to return html opening and closing tag Pin
Richard MacCutchan22-Dec-18 23:35
mveRichard MacCutchan22-Dec-18 23:35 
GeneralRe: how to get a js fuction to return html opening and closing tag Pin
Member 1409810523-Dec-18 14:31
Member 1409810523-Dec-18 14:31 
QuestionGet an html table multiple rows as a string URL for Ajax Pin
Member 1409585019-Dec-18 22:55
Member 1409585019-Dec-18 22:55 
AnswerRe: Get an html table multiple rows as a string URL for Ajax Pin
Afzaal Ahmad Zeeshan23-Dec-18 0:29
professionalAfzaal Ahmad Zeeshan23-Dec-18 0:29 
Questiondebug shopping cart project Pin
ghazabaz13-Dec-18 15:56
ghazabaz13-Dec-18 15:56 
Hello guys,

My final project is almost complete. It is a sub website and the goal is to add items to the cart and calculate if the items has been added or not etc.

Here is what I have so far:

window.addEventListener("load", setupCart);

function setupCart() {
	var addButtons = document.getElementsByClassName("addButton");
	
	for (var i = 0; i < addButtons.length; i++) {
		addButtons[i].addEventListener(addItem);
	}
}

function addItem(e) {
	var foodItem = e.target.nextElementSibling;
	var foodID = foodItem.getAttribute("id").value;
	var foodDescription = foodItem.cloneNode(true);
	var cartBox = document.getElementById("cart");
	
	var duplicateOrder = false;
	
	for (var i = 0; i < cartBox.childNodes.length; i++) {
		if (cartBox.childNodes[i].id === foodID) {
			cartBox.firstElementChild.value + 1;
		}
	}
	
	if (duplicateOrder === false) {
		var orderCount = document.createElement("span");
		orderCount.textContent = 1;
		foodDescription.appendChild(orderCount);
		cartBox.appendChild(foodDescription);
	}
}


I am getting an error on the browsers debug window saying:
Quote:
SCRIPT65535: SCRIPT65535: Argument not optional


For the following code:
addButtons[i].addEventListener(addItem);


Thanks !


***EDIT***

Found a bug:

addButtons[i].addEventListener(addItem);


Updated to:

addButtons[i].addEventListener("click", addItem);


Now items are loading onto cart, but repeat items are NOT simply being added by number, rather a duplicate fills the cart if the original is already there.

Working on this now. Debugger shows no error however.

modified 13-Dec-18 22:27pm.

Questione.target.value, switch-case operators Pin
ghazabaz6-Dec-18 19:22
ghazabaz6-Dec-18 19:22 
QuestionRe: e.target.value, switch-case operators Pin
Richard MacCutchan6-Dec-18 23:26
mveRichard MacCutchan6-Dec-18 23:26 
QuestionRe: e.target.value, switch-case operators Pin
ghazabaz7-Dec-18 3:47
ghazabaz7-Dec-18 3:47 
AnswerRe: e.target.value, switch-case operators Pin
Richard MacCutchan7-Dec-18 4:29
mveRichard MacCutchan7-Dec-18 4:29 
AnswerRe: e.target.value, switch-case operators Pin
Richard Deeming7-Dec-18 5:37
mveRichard Deeming7-Dec-18 5:37 
QuestionRe: e.target.value, switch-case operators Pin
ghazabaz7-Dec-18 6:44
ghazabaz7-Dec-18 6:44 
AnswerRe: e.target.value, switch-case operators Pin
Richard Deeming7-Dec-18 6:51
mveRichard Deeming7-Dec-18 6:51 
AnswerRe: e.target.value, switch-case operators Pin
Richard Deeming7-Dec-18 6:54
mveRichard Deeming7-Dec-18 6:54 
QuestionRe: e.target.value, switch-case operators Pin
ghazabaz8-Dec-18 5:19
ghazabaz8-Dec-18 5:19 
AnswerRe: e.target.value, switch-case operators Pin
Richard Deeming11-Dec-18 1:16
mveRichard Deeming11-Dec-18 1:16 
PraiseRe: e.target.value, switch-case operators Pin
ghazabaz13-Dec-18 6:05
ghazabaz13-Dec-18 6:05 
QuestionEasy HTML Editor Pin
Bram van Kampen3-Dec-18 15:23
Bram van Kampen3-Dec-18 15:23 
AnswerRe: Easy HTML Editor Pin
Nathan Minier6-Dec-18 1:24
professionalNathan Minier6-Dec-18 1:24 
AnswerRe: Easy HTML Editor Pin
Nitin S7-Dec-18 1:57
professionalNitin S7-Dec-18 1:57 
AnswerRe: Easy HTML Editor Pin
RedDk28-Dec-18 11:44
RedDk28-Dec-18 11:44 
GeneralRe: Easy HTML Editor Pin
Bram van Kampen28-Dec-18 12:55
Bram van Kampen28-Dec-18 12:55 
QuestionProblems to obtain value "0" or "1" from a div Pin
serenimus1-Dec-18 0:37
serenimus1-Dec-18 0:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.