I´m traying to get values from my selectpicker. i can select any options and this options have personaliced attr:
<option value="{{ $treatment->id }}" data-tokens="{{ $treatment->id }}" data-price="{{ $treatment->session_price }}">{{ $treatment->treatment_name }}</option>
i need get data-price
to do this, i´m doing:
let e = document.getElementById('treatmentCSelect');
e.addEventListener('change', function(event){
let value = this.getAttribute("data-price");
let selectedOption = e.options[e.selectedIndex];
let price = 0;
price = sumar(price, parseInt(selectedOption.getAttribute("data-price")));
console.log(e.options[e.selectedIndex]);
//console.log(parseInt(e.options[e.selectedIndex]));
});
But always return first option (console.log result):
<option value="1" data-tokens="1" data-price="500">bbbb</option>
My question it´s. How i can to do to amount data-price when i select options?
2
Answers
The problem is that you’re trying to retrieve the data-price attribute from the element itself, rather than from the selected element. Try below approach
Try this: Utilising
multiple
in the select dropdown.