i trying access values assigned in javascript in select_tag.
my javascript following:
function select_pk2(cell){ var val = $('#query_form_opt_'+cell+'_1').val(); var t = $('#query_form_select_ops').val() var opts = json.parse($('#query_form_select_ops').val()); var pk2 = json.stringify(opts[val]["rows"]) var pk3 = json.stringify(opts[val]["cols"]) $('#query_form_opt_'+cell+'_2').val(pk2) $('#query_form_opt_'+cell+'_3').val(pk3) } </script>
pk2 , pk3 arrays (like pk2 = ["aa","bb"]), expected
<%= select_tag "query_form[opt][#{row}][2]", :class => "table_column_width_2" %> <%= select_tag "query_form[opt][#{row}][3]", :class => "table_column_width_2" %>
would have values assigned them in javascript, namely pk2 , pk3, somehow not working. how should assigned values select_tag given id (query_form_opt_)?
if want select value in selected box should use value of option. adding options select box should create option element. looks like:
$.each(pk2, function(value) { $('#query_form_opt_'+cell+'_2') .append($("<option></option>") .attr("value", value) .text(value)); });
for select options in select box:
$('#query_form_opt_'+cell+'_2').val(pk2[position_of_option_to_select])
hope helps.
Comments
Post a Comment