Hi All,
I want to use observe_field on multiple select box.
following is my code
<%= select_tag ''usa[states][]'',
options_from_collection_for_select(state, :state, :state, nil),
:multiple => true, :class=>"multi_select" %>
<%= observe_field :usa_states_ , :url
=>{:controller=>"logins",:action
=>''multi_select_city'', :id=>''1''},
:update=> ''deliverable_city'' , :with
=> "''
state=''+document.getElementById(''usa_states_'').value+''&type=restaurant''",
:on=>''click'' %>
I want to select the city of the different State i selected through
multiple select box.
My problem is that i get only one value of a state when i click the
multiple states i don''t where i''m goin wrong.
Is it possible to use observe_field on multiple select box?
Thanks & Regards,
Salil Gaikwad
--
Posted via http://www.ruby-forum.com/.
$(''usa_states_'').value will return the first selected
item''s value.
It doesn''t matter if it is a multiple select. Change your UI a bit.
On Sep 16, 11:13 am, Salil Gaikwad
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hi All,
>
> I want to use observe_field on multiple select box.
> following is my code
>
> <%= select_tag ''usa[states][]'',
> options_from_collection_for_select(state, :state, :state, nil),
> :multiple => true, :class=>"multi_select" %>
> <%= observe_field :usa_states_ , :url
=>{:controller=>"logins",:action
> =>''multi_select_city'', :id=>''1''},
:update=> ''deliverable_city'' , :with
> => "''
>
state=''+document.getElementById(''usa_states_'').value+''&type=restaurant''",
> :on=>''click'' %>
>
> I want to select the city of the different State i selected through
> multiple select box.
> My problem is that i get only one value of a state when i click the
> multiple states i don''t where i''m goin wrong.
> Is it possible to use observe_field on multiple select box?
>
> Thanks & Regards,
>
> Salil Gaikwad
> --
> Posted viahttp://www.ruby-forum.com/.
Hi All,
I found out the solution for this using following link.
1) http://www.mredkj.com/tutorials/tutorial004.html
2) use following javascript to find out how many options are selected
and pass it thorugh observe field.
<script language="JavaScript" type="text/javascript">
function loopSelected(id)
{
var selectedArray = new Array();
var selObj = document.getElementById(id);
var i;
var count = 0;
for (i=0; i<selObj.options.length; i++) {
if (selObj.options[i].selected) {
selectedArray[count] = selObj.options[i].value;
count++;
}
}
return selectedArray;
}
</script>
Thanks & Regards,
Salil Gaikwad
--
Posted via http://www.ruby-forum.com/.