Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Update textfield using a selectbox in ruby on rails

I am new to rails and I have a form below where I need to update a text field(car price) using the option selected in the select box (adjust price). drop down needs to have multiple percentage option like 100% , 50% and 25%. when one percentage is selected then it should update the car price in the field with new calculated adjusted price.

<% car =  Car.find(params[:id]) %>

<table class="part" width="100%">
  <tr style="vertical-align: top;">
    <td><b>Car Model</b></td>
    <td><b>Price</b></td>
    <td><b>Adjusted price</b></td>
 </tr>

<tr style="vertical-align: top;">
  <td><%= text_field(‘Car’, ‘car_name’, size: 10, value: check_for_car_name(car.name)) %></td>
  <td><%= text_field(‘Car’, ‘price’, size: 10, value: check_for_car_price(car.price)) %></td>
  <td><%= select(adjusted price(not sure of this part)) %></td>
</tr>

</table>

I am not sure about the select box that how I can update the car price on the fly ? Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Have a look at rails guides, you can use options_for_select combined with select_tag

<%= select_tag(:city_id, options_for_select([["25%", 1], ["50%", 2]])) %> 

this will output

<option value="1">25%</option>
<option value="2">50%</option>

Now, to update the price dynamically you'll probably want to use javascript in your front-end for example by adding an event listener to your select. Then, when selected option is for example 50% you can do calculations directly on the price field by changing it's value.

document.getElementById('price').value = calculated price

or as the question was marked for jQuery you can use .val()

$("#price").val() = calculated price
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!