...

View Full Version : Total price using jQuery



alandala
11-20-2010, 01:36 PM
Hello guys,

I'm having some problems with jquery.. What I'm trying to do is, a jquery script to show in real time the total price.

I got this:



<li>Users</li>
<li>
<select name="users" id="users">
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
</select>
</li>

<li>Months</li>
<li>
<select name="months" id="months">
<option value='1'>1 Month</option>
<option value='2'>2 Months</option>
<option value='3'>3 Months</option>
<option value='4'>4 Months</option>
<option value='5'>5 Months</option>
<option value='6'>6 Months</option>
<option value='7'>7 Months</option>
<option value='8'>8 Months </option>
<option value='9'>9 Months</option>
<option value='10'>10 Months</option>
<option value="11">11 Months</option>
<option value="12">12 Months</option>
</select>
</li>

<div class="grand_total">
<h4 class="colr">Price</h4>
<ul>
<li class="price">$0.50</li>
</ul>
</div>


1 Month and 1 User price should be 0.50 USD

+1 Month = + 0.50 USD
+ 1 User = + 0.50 USD

Example: 5 Users + 2 Months = 3.50 USD

I wanna make the jquery to show the total price at li class="price"

Sorry, I'm newbie at jquery. Anyone could help me please?

Thank you.

Philip M
11-20-2010, 02:07 PM
1 Month and 1 User price should be 0.50 USD

+1 Month = + 0.50 USD
+ 1 User = + 0.50 USD

Example: 5 Users + 2 Months = 3.50 USD


This is not jQuery, simple JavaScript.


<li>Users</li>
<li>
<select name="users" id="users" onchange = "calcPrice()">
<option value = "0">Select Number Of Users</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
</select>
</li>

<li>Months</li>
<li>
<select name="months" id="months" onchange = "calcPrice()">
<option value = "0">Select Number Of Months</option>
<option value='1'>1 Month</option>
<option value='2'>2 Months</option>
<option value='3'>3 Months</option>
<option value='4'>4 Months</option>
<option value='5'>5 Months</option>
<option value='6'>6 Months</option>
<option value='7'>7 Months</option>
<option value='8'>8 Months </option>
<option value='9'>9 Months</option>
<option value='10'>10 Months</option>
<option value="11">11 Months</option>
<option value="12">12 Months</option>
</select>
</li>

<div class="grand_total">
<h4 class="colr">Price</h4>
<ul>
<li id = "grdtot" class="price">$0.00</li>
</ul>
</div>

<script type = "text/javascript">
function calcPrice() {
document.getElementById("grdtot").innerHTML = "$0.00";
var u = parseInt(document.getElementById("users").value);
var m = parseInt(document.getElementById("months").value);
if (u && m) {
var gt =(u + m)/2;
document.getElementById("grdtot").innerHTML = "$" + gt.toFixed(2);
}
}
</script>


"The only thing to do with good advice is pass it on. It is never any use to oneself." - Oscar Wilde (Irish Poet, Novelist, Dramatist and Critic, 1854-1900)

alandala
11-20-2010, 03:22 PM
This is not jQuery, simple JavaScript.


<li>Users</li>
<li>
<select name="users" id="users" onchange = "calcPrice()">
<option value = "0">Select Number Of Users</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
</select>
</li>

<li>Months</li>
<li>
<select name="months" id="months" onchange = "calcPrice()">
<option value = "0">Select Number Of Months</option>
<option value='1'>1 Month</option>
<option value='2'>2 Months</option>
<option value='3'>3 Months</option>
<option value='4'>4 Months</option>
<option value='5'>5 Months</option>
<option value='6'>6 Months</option>
<option value='7'>7 Months</option>
<option value='8'>8 Months </option>
<option value='9'>9 Months</option>
<option value='10'>10 Months</option>
<option value="11">11 Months</option>
<option value="12">12 Months</option>
</select>
</li>

<div class="grand_total">
<h4 class="colr">Price</h4>
<ul>
<li id = "grdtot" class="price">$0.00</li>
</ul>
</div>

<script type = "text/javascript">
function calcPrice() {
document.getElementById("grdtot").innerHTML = "$0.00";
var u = parseInt(document.getElementById("users").value);
var m = parseInt(document.getElementById("months").value);
if (u && m) {
var gt =(u + m)/2;
document.getElementById("grdtot").innerHTML = "$" + gt.toFixed(2);
}
}
</script>


"The only thing to do with good advice is pass it on. It is never any use to oneself." - Oscar Wilde (Irish Poet, Novelist, Dramatist and Critic, 1854-1900)

yes.. Sorry! and thank you very much! But there's still a problem.

Look: http://baiserver.com/page.html

Try to select first the number of users and u'll see that price still stays. But the period works..

Philip M
11-20-2010, 03:49 PM
Try to select first the number of users and u'll see that price still stays. But the period works..

Well, yes. It makes no sense to calculate a price unless both the number of users and the number of months have been selected.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum