0

First of all I am getting in javascript the value of a field when selecting a row of a table like this:

  $("#container tr").dblclick(function(){
     $(this).addClass('selected').siblings().removeClass('selected');
     var RutaId=$(this).find('.RutaId').html();
     $("#RutaId").val(RutaId);
  });

it works perfect because it takes the value I require but now I am incorporating in rails a method in the text field like this:

    <%= text_field_tag :search, "", id:"RutaId", class:"", style: "", :'data-remote' => 'true', :'data-url' => url_for(:controller => 'reldaycli', :action => 'busqueda_vendedores_por_ruta', format: 'js')  %>

that will look for records depending on the value, but it does not work When the value change with the code of javascript, only when I write in the field itself, how could I fix it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
jeff
  • 367
  • 4
  • 19
  • 1
    Feel like I'm missing something; could you try and clarify a little more what exactly isn't working with that `text_field_tag` and the javascript? I see you're able to get the value for `RutaId` with the js...but then is it not setting it into the `text_field_tag` or is something else supposed to be happening? – Simple Lime Jul 25 '17 at 02:47
  • @SimpleLime Thanks for replying, I get the value but it is not sending me the parameter because it does not respond the method this way unless I write it myself in the textfield or modify the value added of the javascript – jeff Jul 25 '17 at 03:20
  • so you have like an 'on change' event or something listening to the `text_field_tag` and send it off to the rails app? – Simple Lime Jul 25 '17 at 03:22
  • huh I guess [data-remote and data-url](http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html#data-url-and-data-params) on input fields automagically set things up in rails. I've never seen that done and just assume they weren't doing anything on their own. It's probably using a on change underneath to send it along, check out [val() doesn't trigger change() in jquery](https://stackoverflow.com/questions/3179385/val-doesnt-trigger-change-in-jquery) – Simple Lime Jul 25 '17 at 03:26
  • @SimpleLime thanks a lot, It worked for me – jeff Jul 25 '17 at 14:09
  • @SimpleLime It works for me but the strange thing is that the parameter sends it twice in this way, why could it be? – jeff Jul 25 '17 at 14:47

0 Answers0