jquery change function

12 views
Skip to first unread message

fugee ohu

unread,
Nov 30, 2015, 6:58:04 PM11/30/15
to Ruby on Rails: Talk
this snippet which follows another code block under       $(document).ready(function () {    isn't working, the previous block works, but not this one

  $('#listing_free_shipping').change(function(e)
   {
    if (e.listing_free_shipping.attr('checked'))
     {
     $("#listing_shipping_cost").toggle( "blind" );
     }
    else
     {
     $("#listing_shipping_cost").show();
     }
  })

Colin Law

unread,
Dec 1, 2015, 6:31:16 AM12/1/15
to Ruby on Rails: Talk
Just a couple of notes. The likely reason you have not had any offers
of help with these questions is that it is absolutely nothing to do
with Ruby or Rails, except for the fact that if you are finding that
document ready works sometimes but not others then this is likely due
to the fact that document ready is not compatible with turbolinks (if
you are using that). Google will explain what to do about it.

The other point I would make is that javascript should not normally be
included in the page, it should be in separate assets files.

Colin
Message has been deleted

fugee ohu

unread,
Dec 1, 2015, 8:12:55 AM12/1/15
to Ruby on Rails: Talk

  Commenting out turbolinks in my gemfile didn't help Also, how do i  move my javascript to separate assets files

Colin Law

unread,
Dec 1, 2015, 8:26:40 AM12/1/15
to Ruby on Rails: Talk
On 1 December 2015 at 13:12, fugee ohu <fuge...@gmail.com> wrote:
>
> Commenting out turbolinks in my gemfile didn't help

Assuming that you also did bundle install then it is not that problem,
so it is likely just a problem with the javascript. You probably need
to research how to debug js. Start by sprinkling assert statements
through the code. But as I said debugging js is not what this list is
for.

> Also, how do i move
> my javascript to separate assets files

Do you mean you don't know how to code js so that it resides in
separate files (which is not a ROR issue) or you specifically don't
know how to use the rails assets. If the latter then [1] should help.

Note that the fact that you have included the js in the web page is
not likely to be the cause of your problem, it should work there but
it is considered poor practice.

Colin

[1] http://guides.rubyonrails.org/asset_pipeline.html

fugee ohu

unread,
Dec 1, 2015, 10:32:05 AM12/1/15
to Ruby on Rails: Talk
both
Reply all
Reply to author
Forward
0 new messages