jessicacanuto

JS select options

Dec 9th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. $(document).ready(function(){
  2. var tipo_selected;
  3. changeTipo();
  4. changeProduto();
  5. });
  6.  
  7. function changeTipo(){
  8. $("#tipo-produto").change(function(data){
  9. tipo_selected = data.target.selectedOptions[0].value;
  10. alterSelectProdutos(tipo_selected);
  11. });
  12. }
  13.  
  14. function changeProduto(){
  15. $('#produto-manual').change(function(data){
  16. var produto_selected = data.target.selectedOptions[0].getAttribute("data-tipo");
  17. console.log(produto_selected, tipo_selected);
  18.  
  19. if (produto_selected == tipo_selected) {
  20. $("#go").click(function () {
  21. console.log("Button event registered!");
  22. location.href = "https://google.com"
  23. });
  24. }
  25.  
  26. });
  27. }
  28.  
  29. function alterSelectProdutos(tipo_selected){
  30. $('#produto-manual options').hide();
  31.  
  32. $('#produto-manual option').each(function(index, data){
  33. // console.log(this);
  34. // console.log('Option:'+$(this).attr('data-tipo')+' selected:'+ tipo_selected);
  35.  
  36. if($(this).attr('data-tipo') == tipo_selected){
  37. $(this).show();
  38. }else{
  39. $(this).hide();
  40. }
  41.  
  42. });
  43. $("#produto-manual option:first").prop('selectedIndex',0);
  44. }
Add Comment
Please, Sign In to add comment