Drew Rush
Drew Rush

Reputation: 720

Rails and jQuery

Here is my select box rails code:

<%= collection_select(:dimension_version, :dimension_id, Dimension.all, :id, :title) %>

Which produces:

<select id="dimension_version_dimension_id" name="dimension_version[dimension_id]">

I have jQuery 1.8.1 in my assets/javascripts folder and I'm sure to call it before my application.js.

This is what's in application.js and it does not work:

$(document).ready(function() {
$("#dimension_version_dimension_id").change(function() {
    $("#dave").html('Hello');
  });
});

However, it works if there is no intermediary select.change in there:

$(document).ready(function() {
    $("#dave").html('Hello');
});

So why isn't the first working?

Upvotes: 0

Views: 78

Answers (1)

vijay chouhan
vijay chouhan

Reputation: 1012

$(document).ready(function() {
    $("#dimension_version_dimension_id").bind('change', function()){
        $("#dave").html('Hello');
    }
});

Upvotes: 1

Related Questions