After choosing an option in the selectbox, disable and change the text of two other selectboxes

Asked

Viewed 69 times

1

Beauty guys. I have three selectbox and after choosing in the first Select box the option "Movies", I would like to disable the other two selectbox and modify its text to "N/A":

<select id="categoria" name="categoria">
<option value="1">Animes</option>
<option value="2">Séries</option>
<option value="3">Filmes</option>
</select>

<select id="status" name="status">
<option value="1">Completa(o)</option>
<option value="2">Em exibição</option>
</select>

<select id="episodios" name="episodios">
<option value="02">02 Episódios</option>
<option value="03">03 Episódios</option>
<option value="04">04 Episódios</option>
<option value="05">....</option>
</select>

Thanks in advance.

  • JS pure or jQuery, or whatever?

  • The simplest. The site I’m doing is very simple.

1 answer

0


You can store the options of selects and then restore with onchange:

var status = $("#status").html();
var episodios = $("#episodios").html();
$("#categoria").on("change", function(){
   if($(this).val() == 3){
      $("#status, #episodios").html("<option value=''>N/A</option>");
   }else{
      $("#status").html(status);
      $("#episodios").html(episodios);
   }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="categoria" name="categoria">
<option value="1">Animes</option>
<option value="2">Séries</option>
<option value="3">Filmes</option>
</select>

<select id="status" name="status">
<option value="1">Completa(o)</option>
<option value="2">Em exibição</option>
</select>

<select id="episodios" name="episodios">
<option value="02">02 Episódios</option>
<option value="03">03 Episódios</option>
<option value="04">04 Episódios</option>
<option value="05">....</option>
</select>

  • It worked 100%. Thank you very much

  • @Márciofernandes Thank you! Obg!

Browser other questions tagged

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