-2

i have this JS code:

$('#subproducts_search input').keyup(function () {
    $.get($('#subproducts_search').attr('action');      
    $('#subproducts_search').serialize(), null, 'script');
    return false;
  });

and i changed it for this:

$('#products_search input').keyup(()->
  $.get($('#products_search').attr('action')   
  $('#products_search').serialize(), null, 'script'))
  return false

but i get:

SyntaxError: [stdin]:9:1: unexpected indentation

someone can help me? thanks

Alien Java
  • 75
  • 2
  • 12
  • @Amadan im sorry i already updated the question my friend – Alien Java Apr 26 '17 at 02:33
  • Your first code block is invalid. –  Apr 26 '17 at 02:39
  • @squint i tried with this tutorial my friend i got the code from there: http://stackoverflow.com/questions/23838777/using-ajax-to-search-sort-and-paginate-in-rails-4 – Alien Java Apr 26 '17 at 02:40
  • 1
    The problem is not with your coffeescript, the javascript you are starting with is wrong as commented above. Anyway to convert JavaScript to CoffeeScript and vice versa there's a great online tool http://js2.coffee/ – Steve Carey Apr 26 '17 at 02:43

2 Answers2

1

Your bracketing was wrong.

$('#products_search input').keyup(()->
  $.get($('#products_search').attr('action')   
  $('#products_search').serialize(), null, 'script')
  return false)

However, I'd probably write it so, without brackets to get confused about:

$('#products_search input').keyup () ->
  $.get $('#products_search').attr('action'),
        $('#products_search').serialize(), null, 'script'
  false
Amadan
  • 191,408
  • 23
  • 240
  • 301
0

There's a site designed to do just that. js2.coffee You write your javascript and it transforms it on the spot.

DevJem
  • 656
  • 1
  • 13
  • 21
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/15950691) – Mike Scotty Apr 26 '17 at 07:38
  • I did not need to critique or receive clarification from the author. They specifically asked "How to change Js code to Coffee code" and I provided a method of doing so. – DevJem Apr 26 '17 at 07:41