Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda