Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda