Be sure to change the 'baseURL' to your common site or you'll get a lot of 'file not found' errors.
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|Almería',
'Cádiz|Cádiz',
'Córdoba|Córdoba',
'Granada|Granada',
'Huelva|Huelva',
'Jaén|Jaén',
'Málaga|Málaga',
'Sevilla|Sevilla'],
['-|-','Huesca|Huesca',
'Teruel|Teruel',
'Zaragoza|Zaragoza'],
['-|-','Asturias|Asturias'],
['-|-','Baleares|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]){
tarr = vector[i].split('|');
select2.options[i].value = tarr[1];
select2.options[i].text = 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>
Could be simplified even more with you last requirement,
but not worth the effort if you are happy with the results.