use option output rather then option value
I have a simple jquery script set up to calculate the cost of services for
a user. the script works great! However, my database side calls to go
another route. How can I use the actual output of the option for the
calculation rather then the value
jquery:
var $selections = $('#selections');
var $selects = $("select").change(function () {
var total = 0;
$selections.empty();
$selects.each(function () {
var $selected = $(this).find("option:selected");
var price = parseFloat($selected.data("price")) || 0;
total += price;
if($selected.val() !== ''){
$('<li />', {
text: $selected.val() +
$(this).parent().clone().children().remove().end().text()+"
" + $selected.data("price")
}).appendTo($selections)
}
})
$(".summary").text('Est. Total $' + total);
})
HTML with PHP:
<select name="rooms" id="Areas">
<option value="" selected="selected">0</option>
@foreach ($room as $rooms)
<option data-price="{{ $rooms->pr_clean }}" value='{{ $rooms->room
}}'>{{ $rooms->room }}</option>
@endforeach
</select>
Basically I want to be able to add something different in the value field
to go into the database but still calculate how many room they are wanting
to select using {{ $rooms->room }}
here is a fiddle with the basic idea of how my script works.
http://jsfiddle.net/arunpjohny/xf9Fp/
No comments:
Post a Comment