Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Total price using jQuery

    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:

    Code:
    	 <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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,909
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by alandala View Post
    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.

    Code:
    <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)

  • Users who have thanked Philip M for this post:

    alandala (11-20-2010)

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    This is not jQuery, simple JavaScript.

    Code:
    <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..

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,909
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by alandala View Post
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •