how use jquery to get selected value using simple form of ruby on rails
You should do like this
= towns_select_tag(:statistic, :commune, {include_blank: true}, {class: 'form-control'}, :id => "statistic_commune")
You should get value by using:
$('#statistic_commune').val();
Give input field a value with Jquery in Ruby on Rails
The code below is not picking up the input field:
$('td.input.workload', row).val((price / 125).toFixed(2))
this rule is trying to set a value on td element that have class "input workload" like this.
<table><tr><td class="input workload">is trying to set value here</td></tr></table>
I create a fiddle with an example to set value for all input.
https://jsfiddle.net/tjecuh3m/
I hope I've helped.
How to use jquery variables in ruby?
Your expectations are completely wrong - Ruby (ERB) is executed on the server while this javascript is executed later on the client.
There is no way that you can read a javascript variable on the fly in a javascript erb template. Its just an advanced version of string interpolation, which renders javascript just the same way as it does HTML. It does not actually execute the resulting code.
A better alternative is just to use ERB to produce a template string and modify the elements with javascript.
var x = 1;
$(add_button).click(function(e){ //on add input button click
var $template = $('<div class="sampleclass"><%= f.label :phone", class: "control-label col-md-3" %><div class="col-md-8"><%= f.text_field :phone, class: "form-control" %><a href="#" class="remove_field">Remove</a></div></div>');
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++;
$template.find('label').text("phone " + x);
$template.find('input').attr(name: "phone_" + x);
$(wrapper).append(template); //add input box
}
});
Getting each i element of a ruby array in a javascript function (escaping and unescaping)?
Both of these will escape js.
You can try:
var javascriptArray = <%= escape_javascript ruby_array.to_json %>
or
var javascriptArray = <%= j ruby_array.to_json %>
Related Topics
Get Number Days in a Specified Month Using JavaScript
Accessing ASP.NET Controls Using Jquery (All Options)
Rake Db:Create - Could Not Find a JavaScript Runtime
Parsing JSON Giving "Unexpected Token O" Error
Open File Dialog Box in JavaScript
How to Make a Shared State Between Two React Components
Which Ecmascript 6 Features Imply Strict Mode
Understanding Asynchronous Code in Layman's Terms
Convert a Number into a Roman Numeral in JavaScript
How to Plug a JavaScript Engine with Ruby and Nokogiri
No-JavaScript Detection Script + Redirect
Ruby on Rails 4 JavaScript Not Executed
Jquery or JavaScript to Find Memory Usage of Page