F. LK
F. LK

Reputation: 75

Give input field a value with Jquery in Ruby on Rails

I want to give a set of input fields a value. It's not clear in advance how many input fields have to be filled in, but they all have the same class

When I call the id of the first input field like this it works:

$('#order_order_articles_attributes_0_workload', row).val((price / 125).toFixed(2))

When I call the class like this it doesn't work:

$('td.input.workload', row).val((price / 125).toFixed(2))

The haml code looks like this:

%td.input.workload= order_article_f.input :workload, value: "0", label: false, input_html: { class: 'article_workload' }

How can I get this working for the class?

Upvotes: 0

Views: 946

Answers (1)

lcercal
lcercal

Reputation: 36

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.

Upvotes: 2

Related Questions