On Mar 27, 2012, at 8:46 PM, Cluter Vipic wrote:

> Thanks for the answers,
> 
> follow the source web page, I have:
> 
> <label for="table_basket">Basket</label>
> <select id="table_basket" name="table[basket]"><option value="">Please
> select</option>
> <option value="1">Awesome</option>
> <option value="2">Normal</option></select>
> 
> <label for="table_apple">Apple</label>
> <select id="table_apple" name="table[apple]"><option value="">Please
> select</option>
> <option value="1">Green</option>
> <option value="1">Red</option>
> <option value="2">Yellow</option>
> <option value="2">White</option></select>
> 
> <input name="commit" type="submit" value="Create Table" />
> 
> To works I have to pass the right variable in the follow line
> 
> options = $(apple).filter("[label=#{basket}]").html()
> 
> I think the problem is here: label=#{basket}] that variable gone be 1 o
> 2 (check out the option=value in <select id="table_apple"
> name="table[apple]"> menu) this value is function of the Basket choice
> 
> well I think its only this the problem in the
> app/assest/javascript/table.js.coffee file but I don't know if it's only 
> a
> simple syntax error
> 
> jQuery ->
>  apple = $('#table_apple').html()
>  $('#table_basket').change ->
>    basket = $('#table_basket :selected').text()
>    options = $(apple).filter("[label=#{basket}]").html()
>    if options
>      $('#table_apple').html(options)

You can't just do this, not unless behind the scenes, jQuery is imputing that 
the array is an array of select options, and that the target is a select, and 
is magic-ly and silently doing the Right Thing™ and building new Option objects 
and inserting them in the select. Really, I'm not kidding here, this is not 
going to work in any or many browsers. 

I would love to be wrong about this, but as far as I know, you MUST:

1. Zero the length of the select object. 
2. One at a time, create a new Option object, assign it the desired value and 
text, and add it to the select's options array.

After you have done those things, in that order, you will have a working select 
with the new options.

I know it doesn't look cool to have that old-school bare JavaScript hanging out 
in your CoffeeScript, but really, needs must.

>    else
>      $('#table_apple').empty()
> 
> thanks a lot anyway

You're welcome,

Walter

> 
> C
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to