in rails, i have a nested attribute for selection, different dropdown of same id & name. I'm forming an array for each id of selected options through the javascript function 'hoho'. There is no blank option so the options should be selected once page is loaded.
i wanted to immediately form the array once i navigated into the dropdown page, but i only get the array by reloading the page.
is it due to the onload code or turbolink issue with rails? seen somewhere maybe it is related to some page:change code instead?
please advise.. im using mozilla if that will be helpful, thanksss
rails html view
<select name="variant[option_value_ids][]" onchange="hoho()" id="variant_option_value_ids">
<option value="69">apple</option>
<option value="70">orange</option>
</select>
<select name="variant[option_value_ids][]" onchange="hoho()" id="variant_option_value_ids">
<option value="69">apple</option>
<option value="70">orange</option>
</select>
javascript
function hoho() {
var foo = [];
$("[id^=variant_option_value_ids] option:selected").each(function(){
foo.push($(this).val());
});
}
window.onload = hoho;