Make input (textbox) appear, after selecting a certain item in a select MVC C #

1

Good morning,

The idea is that when selecting an item of a select, I see 2 input for the information entry. Mvc does not work with runnat="server", nor can I use visible or disable (or at least I do not know how to use it). I use VS 2013, MVC C #.

Thank you very much in advance

    
asked by koxe_24 27.12.2017 в 13:36
source

1 answer

1

You do not need the intervention of the server to activate / deactivate a control of the view. Use jquery, which runs on the client, to know when the select change and if it has the value you need then you enable the inputs, otherwise you disable it:

$("#mi-select").change(function(){
  if(this.value == 3){ 
    $(".entradas").attr("disabled", false);
  }else{
    $(".entradas").attr("disabled", true);
  }
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<select id="mi-select">
  <option value="1">Opcion 1</option>
  <option value="2">Opcion 2</option>
  <option value="3">Opcion 3 y habilita los inputs</option>
  <option value="4">Opcion 4</option>
 </select>
 
 <div>
  <input type="text" disabled placeholder="input 1" class="entradas" />
  <input type="text" disabled placeholder="input 2" class="entradas" />
 </div>

This gives you the advantage that your page does not have to reload completely to activate / deactivate the inputs.

    
answered by 27.12.2017 / 13:42
source