Reputation: 41614
I've been stuck with this problem for sometime now, I just don't seem to find a way to fix it.I'd really appreciate it if someone could help me.
I have multiple select boxes on 1 page, I need to get the text of the select boxes(which is the qty of an item) and the value of the selectboxes (the price of the item) and the item description which is in a span tag with a class descriptionColor,
and when someone chooses something from the first select box and sth from the second and so on,I need to add the item name, quantity and total price of each item to hidden fields.
so the hidden field would include: for name:qty of item 1 + item1 name,qty of item2 + item2 name ... for price:total price of all items.
<td><span class="descriptions"><span class="descriptionsColor">MIXED SALAD</span></span></td>
<td> </td>
<td class="body">
<select class="select" name="select3" id="select3">
<option value="0">0</option>
<option value="1.99">1</option>
<option value="1.99">2</option>
<option value="1.99">3</option>
<option value="1.99">4</option>
<option value="1.99">5</option>
<option value="1.99">6</option>
<option value="1.99">7</option>
<option value="1.99">8</option>
</select>
</td>
<td><span class="descriptions"><span class="descriptionsColor">ONION RINGS</span></span></td>
<td class="body">10 Pieces</td>
<td><span class="body">
<select class="select" name="select" id="select">
<option value="0">0</option>
<option value="1.99">1</option>
<option value="1.99">2</option>
<option value="1.99">3</option>
<option value="1.99">4</option>
<option value="1.99">5</option>
<option value="1.99">6</option>
<option value="1.99">7</option>
<option value="1.99">8</option>
</select>
</span></td>
..
..
$(function () {
$('#my-add-button-sides').click(function() {
var qty = [];
var price = [];
var items = [];
$('.select').children('option :selected').each(function() {
var $this = $(this);
qty.push($this.text() );
price.push($this.val() );
items.push( ($(this).prevAll(".descriptionsColor").text()) );
});
var randomNumber = Math.floor((Math.random() * 9000)+200);
$('input[name=my-item-id]').val(randomNumber);
$('input[name=my-item-name]').val(items);
$('input[name=my-item-price]').val(price * qty);
});
});
Upvotes: 0
Views: 583
Reputation: 14967
$("#tableid").find(".select").each(funcion(){
alert($(this).val());
});
Upvotes: 0