I'm trying to put "mobiscroll" (a select list) values into a textbox, but three times in one page, the strange thing is that if I choose to view it only one time it's working... Also, how do I make it display the first number even if hasn't been selected by the user? I tried with "selected" after "value" but it isn't working..
http://winegood.it/landing_ristoranti/index.html
Another question, what should I do if I want to multiply only one the result by 2? I'm trying to do it with this example but it isn't working..
var f = document.frm;
f.sel_value.value = sel.options[sel.selectedIndex].value;
doesn't work for two reasons:
The <input name="sel_value">
elements are not within the form. You have an opening <form>
tag, but no close tag, but the form is implicitly closed by the </div>
that closes the <div>
that contains it.
The assignment will only fill in one input, it doesn't automatically loop over all of them like jQuery does.
Try:
$("input[name=sel_value]").val($(sel).val());
To make it fill in these fields when the page loads, you need:
$(function(){
$('#select').scroller({
preset: 'select',
theme: 'default',
display: 'inline',
mode: 'clickpick',
inputClass: 'i-txt'
});
aggiornaHidden($("#select"));
});
To multiply the value before filling in some of the inputs, change those inputs to:
<input type="text" name="sel_value" data-multiply="2" .../>
Change aggiornaHidden
to:
function aggiornaHidden(sel){
$("input[name=sel_value]").each(function() {
var multiply = $(this).data("multiply") || 1;
$(this).val($(sel).val() * multiply);
});
}