html lists - How to get price in jquery and plus into total -
the html code
echo "<ul id='sub'>"; if($set == null){ echo '<li class="blankseat" ></li>'; }
using price according rows
elseif($name=='pink'){ echo '<li class="pink" price="10" title="row'.$val1.'" name="'.val2.'" value="'.$val3.'"></li>'; }
using different price rows
else{ echo '<li class="orange" price="15" title="row'.$val1.'" name="'.$val2.'" value="'.$val3.'"></li>'; } echo "</ul>"; } echo '</div>'; }
jquery code
var total=0; var counter = 0; var limit=5; var price=0; $('li').click(function(e) { var lastliclicked = $(this).attr('id'); var price=$(this).attr('price'); if($(this).hasclass('pink')|| $(this).hasclass('yellow') || $(this).hasclass('orange')) { if(counter < limit-1) {
count clicked aliments in li
counter++; $(this).addclass('booked').removeclass(lastliclicked); document.getelementbyid("democount").innerhtml=counter; } else {
remove counts of elements if unclicked li
$(this).addclass(lastliclicked).removeclass('booked'); counter --; document.getelementbyid("democount").innerhtml=counter; }
getting total
if(counter < limit) { var total= price * counter; document.getelementbyid('demoprice').innerhtml = '$' + total;}});
var total=0; var counter = 0; var limit=5; var price=0; $('li').click(function(e) { var lastliclicked = $(this).attr('id'); var price=$(this).attr('price'); if($(this).hasclass('pink')|| $(this).hasclass('yellow') || $(this).hasclass('orange')) { if(counter < limit-1) { counter++; $(this).addclass('booked').removeclass(lastliclicked); document.getelementbyid("democount").innerhtml=counter; } else { $(this).addclass(lastliclicked).removeclass('booked'); counter --; $('#democount').val(counter); } if(counter < limit) { /*alert(price)*/ var total= parsefloat(price * counter); document.getelementbyid('demoprice').innerhtml = '$' + total; } } })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div><ul id='sub'> <li class="blankseat" >blankseat</li> <li class="pink" price="10" title="row pink'" name="pink" value="pink">pink</li> <li class="orange" price="15" title="row orange" name="orange" value="orange">orange</li> </ul> </div> <div id="democount"></div> <div id="demoprice"></div>
please try
var total= parsefloat(price * counter);
Comments
Post a Comment