select box question

Discussion in 'Ruby' started by Shanan Suding, Aug 7, 2006.

  1. Hi,

    Yet another newbie here... I'm writing an appliction in Rails, and I've
    Ajaxified my select boxes so they update dynamically. I used the
    "observe_field" method to monitor changes to my select box. I find that
    it's kind of erratic... it updates constantly and makes the selection
    for me, based on where my mouse happens to be hovering when it does its
    observation. Not very user friendly. I'd much rather the onChange
    event, but I'm not sure exactly how to write the syntax for using the event.

    Here's my code as it is now:

    <select id="product[proddesc_pk]" name="product[proddesc_pk]">
    <%= options_from_collection_for_select(
    Product.find_all, "proddesc_pk", "prod_name"
    ) %>
    </select></p>
    <%= observe_field("product[proddesc_pk]",
    :frequency =>0.25,
    :update => "component_id_list",
    :url => { :action => :fill_component_box},
    :with => "'id='+value")
    %>

    How would I go about changing that code so that it updates based on an
    onChange event, rather than the observation?

    Any help would be greatly appreciated!

    Thanks,
    ~ Shanan
    Shanan Suding, Aug 7, 2006
    #1
    1. Advertising

  2. Shanan Suding

    Jan Svitok Guest

    Hi,

    On 8/7/06, Shanan Suding <> wrote:
    > Hi,
    >
    > Yet another newbie here... I'm writing an appliction in Rails, and I've
    > Ajaxified my select boxes so they update dynamically. I used the
    > "observe_field" method to monitor changes to my select box. I find that
    > it's kind of erratic... it updates constantly and makes the selection
    > for me, based on where my mouse happens to be hovering when it does its
    > observation. Not very user friendly. I'd much rather the onChange
    > event, but I'm not sure exactly how to write the syntax for using the event.
    >
    > Here's my code as it is now:
    >
    > <select id="product[proddesc_pk]" name="product[proddesc_pk]">
    > <%= options_from_collection_for_select(
    > Product.find_all, "proddesc_pk", "prod_name"
    > ) %>
    > </select></p>
    > <%= observe_field("product[proddesc_pk]",
    > :frequency =>0.25,
    > :update => "component_id_list",
    > :url => { :action => :fill_component_box},
    > :with => "'id='+value")
    > %>
    >
    > How would I go about changing that code so that it updates based on an
    > onChange event, rather than the observation?
    >
    > Any help would be greatly appreciated!
    >
    > Thanks,
    > ~ Shanan


    If you ask directly on rails forum (http://rubyonrails.com/community)
    it's possible that you'll receive an answer sooner, as there are more
    folks who know ;-)

    J.
    Jan Svitok, Aug 7, 2006
    #2
    1. Advertising

  3. On Aug 7, 2006, at 11:00 AM, Shanan Suding wrote:

    > Hi,
    >
    > Yet another newbie here... I'm writing an appliction in Rails, and
    > I've Ajaxified my select boxes so they update dynamically. I used
    > the "observe_field" method to monitor changes to my select box. I
    > find that it's kind of erratic... it updates constantly and makes
    > the selection for me, based on where my mouse happens to be
    > hovering when it does its observation. Not very user friendly.
    > I'd much rather the onChange event, but I'm not sure exactly how to
    > write the syntax for using the event.
    >
    > Here's my code as it is now:
    >
    > <select id="product[proddesc_pk]" name="product[proddesc_pk]">
    > <%= options_from_collection_for_select(
    > Product.find_all, "proddesc_pk", "prod_name"
    > ) %>
    > </select></p>
    > <%= observe_field("product[proddesc_pk]",
    > :frequency =>0.25,
    > :update => "component_id_list",
    > :url => { :action => :fill_component_box},
    > :with => "'id='+value")
    > %>
    >
    > How would I go about changing that code so that it updates based on
    > an onChange event, rather than the observation?
    >
    > Any help would be greatly appreciated!
    >
    > Thanks,
    > ~ Shanan
    >



    Here is how you can use the onchange event which is much nicer to
    work with:

    <%= select_tag( 'product[proddesc_pk]',
    options_from_collection_for_select(

    Product.find_all, "proddesc_pk", "prod_name") ,
    :eek:nchange => remote_function:)with =>
    "'proddesc_pk ='+value",
    :loading => "Element.show('loading-indicator1')",
    :url => { :action => :
    fill_component_box } ) %>


    Doing it that way will put the value in params[: proddesc_pk] for
    you . You can then respond with rjs to fill whatever you need to fill.

    Cheers-
    -EZra
    Ezra Zygmuntowicz, Aug 7, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gnarlodious
    Replies:
    4
    Views:
    17,535
    elizas
    May 5, 2010
  2. Robin
    Replies:
    2
    Views:
    154
    Robin
    Apr 9, 2004
  3. Sy Ys
    Replies:
    0
    Views:
    118
    Sy Ys
    Sep 15, 2007
  4. palmiere
    Replies:
    1
    Views:
    321
    Erwin Moller
    Feb 9, 2004
  5. Ferd Berfel
    Replies:
    4
    Views:
    138
Loading...

Share This Page