Forum Moderators: open
Thank you!
<script language="javascript">
function switch_language()
{
if (document.form1.select.value == "English") {window.location.href = "http://www...";}
if (document.form1.select.value == "Français") {window.location.href = "http://www...";}
}
</script>
<form name="form1" method="post" action="">
<select name="select" onChange="switch_language()">
<option selected>Français</option>
<option>English</option>
</select>
</form>
<form name="form1" method="post" action="">
<select name="select" onChange="switch_language()">
<option value="Français" selected>Français</option>
<option value="English">English</option>
</select>
</form>
Secondly, to get the value of the selected item, it will be something like this:
function switch_language()
{
if (document.form1.select.options[document.form1.select.selectedIndex].text == "English") {location.href = "http://www...";}
if (document.form1.select.options[document.form1.select.selectedIndex].text == "Français") {location.href = "http://www...";}
}
Note in that example, I used .text instead of .value. This will work with what you have now, if you don't want to use the value="".
The use of the text property has its merits, however.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function switch_language(lang_val){
if(lang_val == "en"){
window.location.href="http. . .";
return;
}
if(lang_val == "fr"){
window.locaton.href="http. . .";
}
return;
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<div>
<select name="select1" onchange="switch_language(this.value)">
<option selected value="fr">Français</option>
<option value="en">English</option>
</select>
</div>
</form>
</body>
</html>
Rambo Tribble: I would have preferred your solution for its simplicity, but does'nt work. While it detects the change of selection (I checked with an alert), it does not jump to the required URL.
ChadSEO: I ended up using your solution, which obviously points out to a few mistakes I made.
Thank you both again!