Check an option when selecting an option from another select Javascript

Asked

Viewed 66 times

1

Hello, I have first select option:

<select name="auto" id="auto">
  <option value="">S/N</option>
  <option value="S">Sim</option>
  <option value="N">Não</option>
</select>

And I also have 2nd select option:

<select name="conta" id="conta">
  <option value="">Selecione</option>
  <option value="+">Somar</option>
  <option value="*">Multiplica</option>
</select>

I have this script but it’s not working, it doesn’t do any action when selecting the option auto.

$('#auto').change(function () {
   const auto = $('#auto').val();
   const conta = $('#conta').val();
   $('#auto').val('');
}).change();

I wish that when I choose any option of first select auto, he put the 2nd select account in the Select option, if you have any other option already selected, you can?

  • It’s because here’s the thing, if I choose any option on select 2 and back in the select 1 and choose any option is for the select 2 he return to the standard state, understood?

1 answer

4


here you are:

$('#auto').change(function(){
  $('#conta').val('');
});
<select name="auto" id="auto">
  <option value="">S/N</option>
  <option value="S">Sim</option>
  <option value="N">Não</option>
</select>

<select name="conta" id="conta">
  <option value="">Selecione</option>
  <option value="+">Somar</option>
  <option value="*">Multiplica</option>
</select>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

  • 2

    Sorry @Augusto Vasques for the direct question without having described something on the subject, I will edit the question stating what I had already produced and did not work.

  • @Aristófanesmelo, do this and you and Mike get my upvote.

  • Edited by @Augusto Vasques.

  • @Aristófanesmelo, Hello. someone had given you the negative, but my positive was zero: https://imgur.com/a/jTACk6C

  • 2

    Vlw and thank you!

Browser other questions tagged

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