Q:

sum values of selected options with initial value

im using this script to do what i need:
HTML
<label id="starting_price">45.00</label>
<select name="price" >
<option value="">Options</option>
<option value="4.00">Small</option>
<option value="8.00">Medium</option>
</select>

EXAMPLE#1
$('select').change(function(){
    var sum = 0;
    $('select :selected').each(function() {
        sum += Number($(this).val());
    });
     $("#starting_price").html(sum);
}); 

The problem im facing is that i want the initial value to be from a label:
EXAMPLE#2
$('select').change(function(){
    var initial = $('#starting_price').html();
    var sum = initial;
    $('select :selected').each(function() {
        sum += Number($(this).val());
    });
     $("#starting_price").html(sum);
}); 

i notice this did not work and it was because it needed to convert the string into a integer so i used this:
EXAMPLE#3
$('select').change(function(){
    var initial = +($('#starting_price').html());
    var sum = initial;
    $('select :selected').each(function() {
        sum += Number($(this).val());
    });
     $("#starting_price").html(sum);
}); 

this are the results:
EXAMPLE#1
Starts from $0.00 if i select a option (example: $4.00) the result is $4.00 if i select the option with no value the result goes back to $0.00.
EXAMPLE#2
NOT WORKING
EXAMPLE#3
Starts from $45.00 if i select a option (example: $4.00) the result is $49.00 if i select the option with no value the result stays in $49.00 when it should go back to $45.00.
How can i make EXAMPLE#3 go back to initial price if option selected is NULL?

A:

You can use a html5 attribute:
<label id="starting_price" data-startprice="45.00">45.00</label>

You can access this with one of these:
$('#starting_price')[0].dataset.startprice (this is native JS, my preferred) or
$('#starting_price').attr('data-startprice') or  $('#starting_price').data('startprice')
Because this doesnt change, you can always get back to it
$('select').change(function(){
    var sum = Number( $('#starting_price')[0].dataset.startprice );// get the data-attribute
    $('select :selected').each(function() {
        sum += Number( $(this).val());
    });
     $("#starting_price").html(sum);
}); 

Here you can find some documentation on data attribute with javascript

