Multiply second value from array to dropdown selected

Multiply second value from array to dropdown selected

I have created a row of drop downs with each option having its own value, as usual.

But what I need to do is multiply a second value per drop down to the options values.

I understand the process of whats needs to be done, but I don't know where or how to add this extra figure in.

Her is it in action in this fiddle - http://jsfiddle.net/c9r48/8/

In the first dropdown for instance it has a label of 'label 1' the options values of:

  1. label: 'Label 1', value: '400', options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }

Then you have that other value in this case 400.

What needs to happen is either the 400 is multiplied straight away to the 12, 6, 4 and 0 or the 400 is multiplied to the selected value, but I cant work out where it goes.

I have used the code below but like I said without much luck -

  1. Math.round(parseInt( x * 100,10)* y)/100;

I have gathered those values here

  1. var sFigure = selectInfo.value;

All the code:

var selects = [
{
label: 'Label 1',
value: '400',
options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }
},
{
label: 'Label 2',
value: '300',
options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }
},
{
label: 'Label 3',
value: '320',
options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }
},
{
label: 'Label 4',
value: '330',
options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }
},
{
label: 'Label 5',
value: '340',
options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }
},
{
label: 'Label 6',
value: '350',
options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }
},
{
label: 'Label 7',
value: '360',
options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }
},
{
label: 'Label 8',
value: '370',
options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }
},
{
label: 'Label 9',
value: '380',
options: { '12': 'Monthly', '6': 'Bi-Monthly', '4': 'Quarterly', '0': 'N/A' }
},
]

$(function () {
$(".addRow").click(addRow)
})
function sum($els) {
var sum = 0;
$els.each(function () {
sum += +$(this).val()
})
return sum
}

function addRow() {
var fieldset = $('<fieldset></fieldset>').appendTo("#test");
var wrapper = $("<div class='formWrapper'></div>").prependTo(fieldset);
var sumDiv = $("<div class='sum'>total £<span>0</span></div>").appendTo(wrapper)

$.each(selects, function (index, selectInfo) {
var label = $("<label class='label'>"+ selectInfo.label +"</label>").prependTo(wrapper);
var sFigure = selectInfo.value;
var select = $("<select class='selectD' name='select" + selectInfo.options +"'></select>").appendTo(label),
optionValues = sortOptions(selectInfo.options);
$.each(optionValues, function (index, value) {
var key = selectInfo.options[value];
$("<option></option>", {
value: value,
text: key
}).appendTo(select)
})
select.change(function () {
fieldset.find("span").text(sum($("select", fieldset)))
$(".sumTotal").find("span").text(sum($("#test select")))
}).change()
});

function sortOptions(options) {
var optionValues = [];

$.each(options, function (value, key) {
optionValues.push(value);
});
function numbersDecreasing(a, b) {
return b - a;
}
optionValues.sort(numbersDecreasing);
return optionValues;

}
}