skip to Main Content

I want to get value of one or more span and just one select tag and get thus the sum and display it in ‘total’ row when submitting.enter image description here . Final aim is to have the sum of items when selected. I added screenshot of my table.

Thanks in advance.

                if ($('#screen').is(":checked")) {
                        $('#screen_display').html($("#screen").val());
                        $('#price_screen').append("300"); 
                   
                    }
                if ($('#garantie').is(":checked")) {
                        $('#garantie_display').html($("#garantie").val());
                        $('#price_garantie').append("200"); 
                    }
                 if ($('#printer').is(":checked")) {
                        $('#printer_display').html($("#printer").val());
                        $('#price_printer').append("100"); 
                    }
                 if ($('#mouse').is(":checked")) {
                        $('#mouse_display').html($("#mouse").val());
                        $('#price_mouse).append("40"); 
                    }
               <select id="select_price" required>
                    <option value="">Please select price</option>
                    <option value="799" class="price" >799</option>
                    <option value="500" class="price" >500</option>
                    <option value="1200"class="price" >1200</option>
                    <option value="1500"class="price" >1500</option>
                </select>
           
                <div>
                    <input type="checkbox" id="screen" value = "screen"/>
                    <label for="screen">screen :</label><span id="300" class="price"> 300</span><br>
                </div>
                <div>
                    <input type="checkbox" id="garantie" value="garantie"/>
                    <label for="garantie">Garantie :</label><span id="200" class="price" >200</span><br>
                </div>
  <div>
                    <input type="checkbox" id="printer" value="printer"/>
                    <label for="printer">Printer :</label><span id="100" class="price" >100</span><br>
                </div>
               <div>
                <input type="checkbox" id="mouse" value="mouse"/>
                <label for="mouse">Mouse fil :</label><span id="40" class="price" >40</span><br><br>
               </div>

I finalise my project

2

Answers


  1. Chosen as BEST ANSWER

    enter image description here

    @RickyGymmadi

    I modified a little, because span class is '.price'. But result is weird

    var span1Value = parseInt($(".price").text());      
    var selectValue = parseInt($("#select_prix").find(":selected").val());    
    var total = span1Value + selectValue;
    

  2. Something like below should work, you can repeat the process for other span elements

    var span1Value = parseInt($("#price_screen").text());    
    var span2Value = parseInt($("#price_garantie").text());    
    var selectValue = parseInt($("#select_price").find(":selected").val());    
    
    var total = span1Value + span2Value + selectValue;
    $('#total').html(total);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search