-1

I use this code for a redirection form when selecting a different jersey from the select input but while the JSfiddle works at my site there is no redirection from the window.location command.

https://jsfiddle.net/giorgoskey/95k1tc0b/4/

function populateSecondTextBox() {
  var p = document.getElementById('your_name');
  var txt = document.getElementById('txtFirst');
  p.textContent = txt.value;
}

function populateNumberTextBox() {
  var p = document.getElementById('your_number');
  var txt = document.getElementById('txtSecond');
  p.textContent = txt.value;
}

var goBtn = document.getElementById("goBtn");
var shirts = document.getElementById("shirts");

goBtn.onclick = function() {
  window.location = shirts.value;
}
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Did you attempt to debug your code using your browser development tools? – gview Oct 25 '21 at 20:14
  • Change the form name to id and di `document.getElementById("cityselect").addEventListener("click", function() { this.action = this.shirts.value; })` – mplungjan Oct 25 '21 at 20:20
  • The code you presented is not the code in your jsfiddle. In that code, your form submits to a function redirectTo, that doesn't exist. you don't [have a minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) here. Update your question so it's complete and reproducible. – gview Oct 25 '21 at 20:40
  • The main issue with this question [has already been answered here](https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage). – gview Oct 25 '21 at 20:44

1 Answers1

0

Hou have to use history.pusthState()

MDM

history.pushState(state, title [, url])

empty state and title.

window.history.pushState({}, '', url);

in your case


var goBtn = document.getElementById("goBtn");
var shirts = document.getElementById("shirts");

goBtn.onclick = function() {
    window.history.pushState({}, '', shirts.value);
}
Robert
  • 2,538
  • 1
  • 9
  • 17