Jump to content

Problems with 'NaN'


Alechko

Recommended Posts

Hello guys,

I have 2 functions that I wrote in JS:

	function changePrice(divId, sId, price) {
	document.getElementById(divId).innerHTML = price * document.getElementById(sId).value + ' ₪';
}

function changeTotal(id1,id2) {
		var a = document.getElementById(id1).value;
		var b = document.getElementById(id2).value;
		document.getElementById('totalSum').innerHTML = Number(a);
}

 

This is the HTML Code:

		<div class="protitle"> Sum </div>		
	<div class="protitle"> Price </div>
	<div class="protitle"> Quanity </div>

	<div class="product-title"> 
		<img src="colors/G.gif" alt=" />
		<a href="#" title="#" style="font-size:15px;text-decoration:underline;">
		<span style="font-weight:bold;"> Printer </span> HP 51626A </a>
	</div>

	<div class="product-sum" id="sum-1"> 1027 ₪</div>
	<div class="product-price"> 678 ₪</div>
	<div class="product-quanity"> 
		<form>
			<select id="selectQuan-1" onChange="changePrice('sum-1','selectQuan-1','678');changeTotal('sum-1','sum-2');">
				<option value="1" checked>1</option>
				<option value="2" checked>2</option>
				<option value="3" checked>3</option>
				<option value="4" checked>4</option>
				<option value="5" checked>5</option>
			</select>
		</form>
	</div>

			<div class="product-title"> 
		<img src="colors/R.gif" alt=" />
		<a href="#" title="#" style="font-size:15px;text-decoration:underline;">
		<span style="font-weight:bold;"> Printer </span> HP 51626A </a>
	</div>

	<div class="product-sum" id="sum-2"> 1027 ₪</div>
	<div class="product-price"> 678 ₪</div>
	<div class="product-quanity"> 
		<form>
			<select id="selectQuan-2" onChange="changePrice('sum-2','selectQuan-2','678');changeTotal('sum-1','sum-2');">
				<option value="1" checked>1</option>
				<option value="2" checked>2</option>
				<option value="3" checked>3</option>
				<option value="4" checked>4</option>
				<option value="5" checked>5</option>
			</select>
		</form>
	</div>

<div class="totalSum" id="totalSum">   </div>

 

I am trying to update automatically the sum in the page. the first function the summing up only the product - working fine.

but when I'm trying to TotalSum it gives me an error with 'NaN'.

I tried to use the parseInt() function and the Number().. but still the 'NaN' pops to me.

 

help someone?

 

Appriciate it. thanks.

Link to comment
https://forums.phpfreaks.com/topic/266331-problems-with-nan/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.