How can I redirect my users to a specific page according to a value when clicking on a button?

Asked By: Anonymous

So i’d like to redirect the user to another page when the button is clicked according to a certain value (for example, if the value is "8", i would like the user to be redirected to the "8.html" page).

I’m using a select to make the user able to choose between the differents values (timezones here)

I tried using if instructions without any success. If anyone knows how to do so it’d help me a lot. Thanks.

Here’s what i got so far :

_x000D_

_x000D_

function redirectTZ() {
  var tz = value

  document.write(tz);

  if (tz == -4);
  window.location.assign("gmt+1.html");
  if (tz == -3);
  window.location.href = "gmt-3.html";
  if (tz == 0);
  window.location.href = "gmt+0.html";
  if (tz == 1);
  window.location.href = "gmt+1.html";
  if (tz == 3);
  window.location.href = "gmt+3.html";
}

_x000D_

<select>
  <option timeZoneId="11" gmtAdjustment="GMT-06:00" useDaylightTime="1" value="-4">(GMT-04:00) Washington</option>
  <option timeZoneId="23" gmtAdjustment="GMT-03:00" useDaylightTime="0" value="-3">(GMT-03:00) Buenos Aires</option>
  <option timeZoneId="30" gmtAdjustment="GMT+00:00" useDaylightTime="1" value="0">(GMT+00:00) Lisbon, London</option>
  <option timeZoneId="30" gmtAdjustment="GMT+00:00" useDaylightTime="1" value="0">(GMT+00:00) Lisbon, London</option>
  <option timeZoneId="33" gmtAdjustment="GMT+01:00" useDaylightTime="1" value="1">(GMT+01:00) Brussel, Copenhagen, Madrid, Paris</option>
  <option timeZoneId="46" gmtAdjustment="GMT+03:00" useDaylightTime="1" value="3">(GMT+03:00) Moscou, St. Petersburg</option>
</select>

<button onclick="redirectTZ()">Valider</button>

_x000D_

_x000D_

x000D


Solution

Answered By: Anonymous

I think this is what you are looking for. I would suggest setting an id to your select, get the selected value and use that value to create the url.

HTML

<select id="select_id">
  <option timeZoneId="11" gmtAdjustment="GMT-06:00" useDaylightTime="1" value="-4">(GMT-04:00) Washington</option>
  <option timeZoneId="23" gmtAdjustment="GMT-03:00" useDaylightTime="0" value="-3">(GMT-03:00) Buenos Aires</option>
  <option timeZoneId="30" gmtAdjustment="GMT+00:00" useDaylightTime="1" value="+0">(GMT+00:00) Lisbon, London</option>
  <option timeZoneId="30" gmtAdjustment="GMT+00:00" useDaylightTime="1" value="+0">(GMT+00:00) Lisbon, London</option>
  <option timeZoneId="33" gmtAdjustment="GMT+01:00" useDaylightTime="1" value="+1">(GMT+01:00) Brussel, Copenhagen, Madrid, Paris</option>
  <option timeZoneId="46" gmtAdjustment="GMT+03:00" useDaylightTime="1" value="+3">(GMT+03:00) Moscou, St. Petersburg</option>
</select>

<button onclick="redirectTZ()">Valider</button>

Javascript

function redirectTZ() {
  // Get the selected value
  var tz = document.getElementById("select_id").value;
  // Redirect user
  window.location.assign("gmt"+tz+".html");
}
techinplanet staff

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno