Paulo Paulo - 25 days ago 5x
Javascript Question

How to make a field To appears only if an option is select, using Rails and JavaScript?

Sorry for my bad english.

I am writing a WebApp using Ruby on Railland and I need a field to be show up only if option is selected.

Here is my form in question:


<div class="field" id="ddlSelect">
<%= f.label "Tipo de Pagamento" %><br>
<%=, options_for_select([['À vista', 1], ['À prazo', 2], ['Misto', 3]]), { include_blank: true }) %>

<input type="text" id="hdnPro" value="product" style='display:none'/>


var ddlSelect;

ddlSelect = function() {
if($(this).val() == 'À prazo' || 'Misto'){


$(document).ready(function() {

Two others questions: how to re-write this line to embedded ruby

<input type="text" id="hdnPro" value="product" style='display:none'/>

And how to connect the _form to gastos.js.



This is how I fixed my code.

              <div class="field">
                <%= f.label "Forma de Pagamento" %><br>
                <%= :forma_pagamento, forma_de_pagamento, { include_blank: true }, { :id => "forma_pagamento"} %>
              <script >
                  if($(this).val() == 1){

                  }if($(this).val() == 2){

                  }if($(this).val() == 3){