Ciao a tutti, non riesco a risolvere questo problema, io ho un form così composto:
codice:
<form name="form2" method="post" action="" onSubmit="return controllo();">
<input name="titolare0" type="hidden" id="titolare0" value="valore_dinamico">
<input name="titolare1" type="hidden" id="titolare1" value="valore_dinamico">
............................
<input name="titolare11" type="hidden" id="titolare11" value="valore_dinamico">

<select name="panchina0" id="panchina0" style="width:250px">
<option value="0">.......</option>
<option value="valore_dinamico">valore_dinamico</option>
.......
serie di option nel menu a tendina
</select>
<select name="panchina1" id="panchina1" style="width:250px">
<option value="0">.......</option>
<option value="valore_dinamico">valore_dinamico</option>
.......
serie di option nel menu a tendina
</select>
.............................
<select name="panchina11" id="panchina11" style="width:250px">
<option value="0">.......</option>
<option value="valore_dinamico">valore_dinamico</option>
.......
serie di option nel menu a tendina
</select>
</form>
In pratica sono 11 campi nascosti con un valore dinamico e 11 select, la mia intenzione è quella di sapere se il valore delle scelte effettuate è contenuto in uno dei campi nascosti, per fare ciò ho fatto una funzione javascript che fa egregiamente il suo dovere, la riporto di seguito:
codice:
<script type="text/javascript">
function controllo(){
if(document.getElementById("panchina0").value == 0){
alert('Seleziona Portiere!');
return false;
}
if(document.getElementById("panchina1").value == 0){
alert('Seleziona Portiere!');
return false;
}
if(document.getElementById("panchina0").value == document.getElementById("panchina1").value){
alert('Hai scelto due portieri uguali in panchina!');
return false;
}
if(document.getElementById("panchina2").value ==0){
alert('Seleziona Difensore!');
return false;
}
if(document.getElementById("panchina3").value ==0){
alert('Seleziona Difensore!');
return false;
}
if(document.getElementById("panchina4").value ==0){
alert('Seleziona Difensore!');
return false;
}
if((document.getElementById("panchina2").value ==document.getElementById("panchina3").value)||(document.getElementById("panchina2").value ==document.getElementById("panchina4").value)||(document.getElementById("panchina3").value ==document.getElementById("panchina4").value)){
alert('Hai selezionato due difensori uguali!');
return false;
}
if(document.getElementById("panchina5").value ==0){
alert('Seleziona Centrocampista!');
return false;
}
if(document.getElementById("panchina6").value ==0){
alert('Seleziona Centrocampista!');
return false;
}
if(document.getElementById("panchina7").value ==0){
alert('Seleziona Centrocampista!');
return false;
}
if((document.getElementById("panchina5").value ==document.getElementById("panchina6").value)||(document.getElementById("panchina5").value ==document.getElementById("panchina7").value)||(document.getElementById("panchina6").value ==document.getElementById("panchina7").value)){
alert('Hai selezionato due centrocampisti uguali!');
return false;
}
if(document.getElementById("panchina8").value ==0){
alert('Seleziona Attaccante!');
return false;
}
if(document.getElementById("panchina9").value ==0){
alert('Seleziona Attaccante!');
return false;
}
if(document.getElementById("panchina10").value ==0){
alert('Seleziona Attaccante!');
return false;
}
if((document.getElementById("panchina8").value ==document.getElementById("panchina9").value)||(document.getElementById("panchina8").value ==document.getElementById("panchina10").value)||(document.getElementById("panchina9").value ==document.getElementById("panchina10").value)){
alert('Hai selezionato due attaccanti uguali!');
return false;
}
for (i=0; i<11; i++){
if((document.getElementById("panchina2").value == document.getElementById("titolare"+[i]).value)||(document.getElementById("panchina3").value == document.getElementById("titolare"+[i]).value)||(document.getElementById("panchina4").value == document.getElementById("titolare"+[i]).value)||(document.getElementById("panchina5").value == document.getElementById("titolare"+[i]).value)||(document.getElementById("panchina6").value == document.getElementById("titolare"+[i]).value)||(document.getElementById("panchina7").value == document.getElementById("titolare"+[i]).value)||(document.getElementById("panchina8").value == document.getElementById("titolare"+[i]).value)||(document.getElementById("panchina9").value == document.getElementById("titolare"+[i]).value)||(document.getElementById("panchina10").value == document.getElementById("titolare"+[i]).value)){
alert('Hai selezionato un giocatore già presente nella formazione titolare!');
return false;
}
}
}
</script>
Il mio problema è che vorrei che mi venisse ridato il focus dell'oggetto selezionato che ha il valore uguale ad uno dei campi nascosti..
per fare ciò ho pensato ad una soluzione del tipo:
document.getElementById("panchina"+[i]).focus();
però questa soluzione non riporta la scelta che ho fatto, ma si riferisce a quale campo nascosto a fatto errore e mi ritorno il focus su un'altra select, come faccio ad avere il focus giusto?

Grazie anticipatamente.