Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I have a list of courses with checkbox options.I need to get the total price as per checkboxes checked and unchecked.I need to apply jquery function to my html page.Please help me out soon.
Posted
Comments
Shubhashish_Mandal 14-Aug-13 2:22am    
To get the price on selected option you have to use asynchronous call and for that purpose you have to use json.

go for this jsfiddle where you will get what you need.
and please do play around with this, so you will understand and can implement in many other scenarios for your better.

http://jsfiddle.net/fQTUp/9/[^]

Cheers
 
Share this answer
 
HTML
<input type="checkbox" value="1000"  name="HTML" id="1"  class="box">HTML<br /><br />
<input type="checkbox"  name="C" value="1500" id="2"  class="box">C#<br /><br />
<input type="checkbox"  name="JQuery" value="2000" id="5"  class="box">JQuery<br /><br />
<input type="button" id="GetTotal" value="Get total amount"><br />


C#
$(document).ready(function(){
    $('#GetTotal').on('click', function(){
  var prices = [];
   $('input:checked').each(function() {

       prices .push($(this).attr("value"));

 });
        var total=0;
   for(var i=0;i<prices.length;i++)
   {
    total=total+parseInt(prices [i]);
   }
   alert("Total amount of selected course are:"+total);
   switch(prices.length)
   {
       case 1:
           alert("10% discount");
           break;
       case 2:
           alert("20% discount");
           break;
       case 3:
           alert("30% discount");
           break;
       default:
           alert("Invalid selection");
   }
 });
});
 
Share this answer
 
v4
Comments
Radhika Vyas 14-Aug-13 5:11am    
Hi Jitendra
I tried ur example...But I am getting error in alert saying '0HTMLundefined'..Are u sure we need to give value in id's...can u please suggest me soon...Thanks for the quick response..
Jitendra Sabat 14-Aug-13 9:39am    
Hi Radhika
Now code is working fit n fine.I have checked it twice.You can go for it...
Radhika Vyas 14-Aug-13 5:34am    
Thank You very much Kishore Sharma..It worked :)
Jitendra Sabat 14-Aug-13 5:43am    
Sorry!....i have not taken price in to consideration.Now in the edited code,it's fine.Thank you.
Radhika Vyas 14-Aug-13 5:47am    
Thanks Jitendra

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900