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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.