RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: Astr0surf3r
Hi guys,
I'm a newbie so in my case my webpage is:
< 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" />
in the app/views/apple/index.html.erb I have
<%= form_for @table do |f| %>
<%= f.label :basket %> <%= f.collection_select :basket, @basket, :id, :name, {:prompt => true} %>
<%= f.label :comune %> <%= f.collection_select :apple, @apple, :basket_id, :name, {:prompt => true} %>
<%= f.submit %>
<% end %>
And I change the apple.js.coffe file in this
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) else $('#table_apple').empty()
but it doesn't work I think the problem it's here in this line
options = $(apple).filter("[label=#{basket}]").html()
options doesn't get the 'value' of the option attribute in the select list menu
Is it a simple syntax error?
thank you in advance,
A
Hi guys,
I'm a newbie so in my case my webpage is:
< 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" />
in the app/views/apple/index.html.erb I have
<%= form_for @table do |f| %>
<%= f.label :basket %>
<%= f.collection_select :basket, @basket, :id, :name, {:prompt => true} %>
<%= f.label :comune %>
<%= f.collection_select :apple, @apple, :basket_id, :name, {:prompt => true} %>
<%= f.submit %>
<% end %>
And I change the apple.js.coffe file in this
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)
else
$('#table_apple').empty()
but it doesn't work I think the problem it's here in this line
options = $(apple).filter("[label=#{basket}]").html()
options doesn't get the 'value' of the option attribute in the select list menu
Is it a simple syntax error?
thank you in advance,
A