Hi, I'm trying to get the value and text of multiple select boxes and add them to a hidden fields, can any one please help.
<form>
<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>
<select class="select" name="select2" id="select2">
<option value="0">0</option>
<option value="2.99">1</option>
<option value="2.99">2</option>
<option value="2.99">3</option>
<option value="2.99">4</option>
<option value="2.99">5</option>
<option value="2.99">6</option>
<option value="2.99">7</option>
<option value="2.99">8</option>
</select>
</form>
$(function() {
//function to go through all of the select boxes and get their values based on their change state.
var qty=0;var price=0;items="";
$(".select").each(function() {
$(this).change(function(){
qty =($(this).text());
price = (($(this).val()) * qty);
items = ($(this).prevAll(".descriptionsColor").text() );
});
});
//function to add items to shopping cart when add button is clicked.
$('#my-add-button').click(function() {
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);
});
I need to get the value and text of the select boxes on change and multiply them to get a price, also get the description of the item which is in a span tag with a class.
Do I need to use array variables to store the values and text and prices?
thanks for any help.