jessicacanuto

COMBINA UM SELECT COM OUTRO

Dec 9th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. $(document).ready(function(){
  2. changeTipo();
  3. changeProduto();
  4. });
  5.  
  6. function changeTipo(){
  7. $("#selectA").change(function(){
  8. var tipo_selected = $( "#selectA option:selected" ).text();
  9. alterSelectProdutos(tipo_selected);
  10.  
  11. });
  12. }
  13.  
  14. function changeProduto(){
  15. $('#selectB').change(function(data){
  16. var produto_selected = $( "#selectB option:selected" ).text();
  17.  
  18. });
  19. }
  20.  
  21. function alterSelectProdutos(tipo_selected){
  22. $('#selectB options').hide();
  23.  
  24. $('#selectB option').each(function(index, data){
  25. console.log(this);
  26. console.log('Option:'+$(this).attr('data-tipo')+' selected:'+ tipo_selected);
  27.  
  28. if($(this).attr('data-tipo') == tipo_selected){
  29. $(this).show();
  30. }else{
  31. $(this).hide();
  32. }
  33.  
  34. });
  35. $("#selectB option:first").prop('selectedIndex',0);
  36. }
Add Comment
Please, Sign In to add comment