First of all, thanks for your patience.....
When i say level options i mean this
1st Level Options (Andalucía, Aragón, Asturias, Baleares)
2nd level options (the ones in the array)
The
first thing i was looking for was a select list with 2 levels with an automatic generated link with a BaseURl + the name of the options, you solved it giving me this code:
Works perfect, but i don't know how to make it to open the links in a new tab instead the same window, that's the only problem i have with that. Hope you can help me with that...
Code:
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<title> Untitled </title>
<script type="text/javascript">
// NOTE: You need to fill in the links as defined by your requirements in the following array elements
var provincias = [
[], // spare (not used in this version of program)
['-','Almería',
'Cádiz',
'Córdoba',
'Granada',
'Huelva',
'Jaén',
'Málaga',
'Sevilla'],
['-','Huesca',
'Teruel',
'Zaragoza'],
['-','Asturias'],
['-','Baleares'] // Note: no comma after final entry
];
function cambiar(formulario){
var i = 0;
var select1 = formulario['D1'];
var select2 = formulario['D2'];
var vector = provincias[select1.selectedIndex];
if(vector.length)select2.length=vector.length;
var tarr = [];
while(vector[i]){
select2.options[i].value = vector[i]; // tarr[1];
select2.options[i].text = vector[i]; // tarr[0];
i++;
}
select2.options[0].selected = 1;
}
function goToSite(info) {
if (info != '-') { alert(info); } // this line is for testing purposes only
// if (info != '-') { document.location.href = info; } // uncomment this line after testing
}
function linkToSite(formulario) {
var select1 = formulario['D1'];
var select2 = formulario['D2'];
var baseURL = 'http://www.codingforums.com/'; // defined as some common URL if same for all links
var str = '';
str = baseURL+select1.value+select2.value+'.html';
goToSite(str);
}
</script>
<style type="text/css">
</style>
</head>
<body>
<form method="POST">
<select name="D1" onchange="cambiar(this.form)">
<option>-</option>
<option>Andalucía</option>
<option>Aragón</option>
<option>Asturias</option>
<option>Baleares</option>
</select>
<select name="D2" onchange="linkToSite(this.form)">
</select></p>
</form>
</body>
</html>
Second
I thought that it would be easy to me to modify the code and eliminate the second level options, to just keep 1 level option but with generating and taking me to the link with a "BaseUrl too + the option", in other words, the same thing that the code i post uo here but just for 1 level option, but i can't, and i don't post any code of that because i suck in javascript stuff..
Thank you