Witam mam poniższy kod który działa w następujący sposób tzn. po wybraniu języka wyświetla się wybór waluty. Po wybraniu $ do adresu ma dopisać wartość "/?currency_id=3"i podobnie przy wyborze €. Mam problem ponieważ chciałbym zrobić tak że jeżeli po wyborze € dopisywało wartość "/?currency_id=2" ale jednocześnie kasowało wartość "/?currency_id=3" jeżeli ktoś wcześniej wybrał $.

  1. <link href="https://fonts.googleapis.com/css?family=Saira+Stencil+One&display=swap" rel="stylesheet">
  2. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  3. <meta name="viewport" content="width=device-width, initial-scale=1">
  4. .content_page2
  5. {
  6. display: none !important;
  7. }
  8. .content_page
  9. {
  10. font-family: 'Saira Stencil One', cursive;
  11. border-radius:10px;
  12. color:#fff;
  13. text-shadow: 2px 2px 6px #000;
  14. background-color: rgba(0,255,255,0.6);
  15. padding: 20px;
  16. position: fixed;
  17. top: 50%;
  18. left: 50%;
  19. transform: translate(-50%, -50%);
  20. display: inline-block;
  21. max-width:480px;
  22. }
  23. <div id="buttom" class="content_page">
  24. <h3 id="info">Wybierz język</h3>
  25. <button id="1" onclick="myFunction(this)"><img class="trp-flag-image" src="https://aldstudio.pl/cars/wp-content/plugins/translatepress-multilingual/assets/images/flags/pl_PL.png" alt="pl_PL" title="Polski" width="18" height="12"></button>
  26. <button id="2" onclick="myFunction(this)"><img class="trp-flag-image" src="https://aldstudio.pl/cars/wp-content/plugins/translatepress-multilingual/assets/images/flags/en_GB.png" alt="en_GB" title="English" width="18" height="12"></button>
  27. <button id="3" onclick="myFunction(this)"><img class="trp-flag-image" src="https://aldstudio.pl/cars/wp-content/plugins/translatepress-multilingual/assets/images/flags/de_DE.png" alt="de_DE" title="Deutsch" width="18" height="12"></button>
  28. <button id="4" onclick="myFunction(this)"><img class="trp-flag-image" src="https://aldstudio.pl/cars/wp-content/plugins/translatepress-multilingual/assets/images/flags/fr_FR.png" alt="fr_FR" title="Français" width="18" height="12"></button>
  29. <button id="5" onclick="myFunction(this)"><img class="trp-flag-image" src="https://aldstudio.pl/cars/wp-content/plugins/translatepress-multilingual/assets/images/flags/ru_RU.png" alt="ru_RU" title="Русский" width="18" height="12"></button>
  30. <div id="mySelect" style="display:none;">
  31. <h3 id="info2"></h3>
  32. <form>
  33. <select id="select_id" name="currency" class="form-control" onclick="myFunctionSecond()">
  34. <option value="1" selected="selected">PLN</option>
  35. <option value="2"> Euro</option>
  36. <option value="3">$ USD</option>
  37. </form>
  38. </div>
  39. <a id="enter" style="display:none;" href="">
  40. <img src="https://www.nicepng.com/png/full/97-971602_click-finger-png-png-royalty-free-stock-finger.png" width="10%"></a></div>
  41.  
  42. function myFunction(button) {
  43.  
  44. document.getElementById('mySelect').style.display = "block";
  45. document.getElementById('enter').style.display = "block";
  46.  
  47. var x = button.id;
  48. switch(x)
  49. {
  50. case '1':
  51. document.getElementById('info').innerHTML = 'Wybierz język';
  52. document.getElementById('info2').innerHTML = 'Wybierz walutę';
  53. document.getElementById("enter").href = "https://aldstudio.pl/cars";
  54. document.getElementById("select_id").value = "1";
  55. break;
  56. case '2':
  57. document.getElementById('info').innerHTML = 'Choose a language';
  58. document.getElementById('info2').innerHTML = 'Select currency';
  59. document.getElementById("enter").href = "https://aldstudio.pl/cars/en";
  60. document.getElementById("select_id").value = "1";
  61. break;
  62. case '3':
  63. document.getElementById('info').innerHTML = 'Sprache auswählen';
  64. document.getElementById('info2').innerHTML = 'Wählen Sie die Währung';
  65. document.getElementById("enter").href = "https://aldstudio.pl/cars/de";
  66. document.getElementById("select_id").value = "1";
  67. break;
  68. case '4':
  69. document.getElementById('info').innerHTML = 'Choisissez la langue';
  70. document.getElementById('info2').innerHTML = 'Choisissez la devise';
  71. document.getElementById("enter").href = "https://aldstudio.pl/cars/fr";
  72. document.getElementById("select_id").value = "1";
  73. break;
  74. case '5':
  75. document.getElementById('info').innerHTML = 'Выберите язык';
  76. document.getElementById('info2').innerHTML = 'Выберите валюту';
  77. document.getElementById("enter").href = "https://aldstudio.pl/cars/ru";
  78. document.getElementById("select_id").value = "1";
  79. break;
  80. }
  81. }
  82. function myFunctionSecond() {
  83. var currency = document.getElementById('select_id').value;
  84. switch (currency) {
  85.  
  86. case '2':
  87. var el = document.getElementById('enter');
  88. el.href += '/?currency_id=2';
  89. break;
  90. case '3':
  91. var el = document.getElementById('enter');
  92. el.href += '/?currency_id=3';
  93. break;
  94. }
  95. var x = document.querySelectorAll(".lp-screen");
  96. x[0].style = "background-color:none !important";
  97. var element = document.getElementById("buttom");
  98. element.classList.add("content_page2");
  99. document.getElementById('mySelect').style.display = "block";
  100.  
  101. }
  102.