How to show a block field a word according to certain parameters?

Asked

Viewed 57 times

0

I need to display a name in a form field with buttons. If the user selects the number 1 in the previous field, in the next field in block mode (so that it is not modifiable by the user), he should display for example the word "row"; if he selects the number 2 he should show for example "counter"...; When the user clicks on the Submit button this information must be stored (the number "1", the word "career" and the others in the database previously created in phpmyadmin).

I leave here the code done until then

  • Be clearer and put code examples than you have done.

1 answer

0


From what I understand you want to validate using the block, see if it fits using jQuery itself. It is very simple and very easy to understand, but if you need some feedback from PHP warns, because it would just be appropriate or check if the Antonio model fits.

jQuery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

HTML

<form id="formulario" method="" action="">
 <select id="opcao">
  <option value="">Selecione a opção</option>
  <option value="1">Opção 1</option>
  <option value="2">Opção 2</option>
 </select>
 <input type="text" id="retorno" disabled />
</form>

Script

$(document).ready(function(){
 $('#opcao').change(function(){
  var selecionado = $(this).val();
  if(selecionado == ""){
   $("#retorno").val("Opção não Selecionada");
  }else{
   if(selecionado == 1){
    $("#retorno").val("Contratro");
   }
   if(selecionado == 2){
    $("#retorno").val("Carreira");
   }
   if(selecionado == 3){
    $("#retorno").val("Outra Opção");
   }
  }
 });
});
  • Exactly, the idea would be something like this but I don’t have much practice with jQuery. I put the code part of the Script in a JS file and made the import but it didn’t work: <script src="options.js"> </script> ; the window appeared with "option 1","option 2" but in the locked field the word Contract/Career did not appear after selected. I also tried doing it directly where I have all the code: <script> script code </script>

  • Did you indicate where the jQuery file is? example: <script type="text/javascript" src="scripts/jquery.js"></script>>

  • last time it failed because the <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" > was missing after it started working. today I tested the same code as it is and it doesn’t work. which might be ?

  • Open in Chrome and check the error console, there should appear something, anything runs here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.