Ciao.
Mi date una mano a capire dove sbaglio?
Questa funzione deve convalidare un form soltanto quando:
1) l' orario è inserito nel formato 'hh:mm'
2) l' orario è inferiore a 7 ore e 36 minuti.
Non funziona, dove sbaglio?
codice:function updateTime(txtObj) { if (window.opener == null) return; // RegExp di validazione oraria var re = /^([01]\d|2[0-3]):[0-5]\d$/; // Visualizza un alert solo se il campo correntemente editato ha almeno 5 caratteri ed è errato if (txtObj.value.length >= 5 && !txtObj.value.match(re)) { alert("Inserire l'orario nel formato 'hh:mm'."); txtObj.focus(); } // Oggetto del FORM e collection dei campi var frmObj = txtObj.form; var elems = frmObj.elements; // Stringa da impostare nel campo 'impiego' del FORM nella window parente // e oggetto del campo 'impiego' del FORM nella window parente var result = ""; var destObj = window.opener.document.myform.impiego; // Il primo campo 'ent' è obbligatorio if (frmObj.ent.value.match(re)) var totalHours = 0; var totalMins = 0; { for ( var n = 0 ; n < elems.length ; n++ ) { // Itera solo i campi di tipo 'text' che contengono un orario corretto if (elems[n].type == "text" && elems[n].value.match(re)) { var vals = elems[n].value.split(":"); var hours = parseInt(vals[0]); var mins = parseInt(vals[1]); totalHours += hours; totalMins += mins; } { if (result.length) result += ";"; result += elems[n].name + "-" + elems[n].value; // aggiungi il separatore } } destObj.value= result; } else destObj.value= "--:--";// Stringa di errore if (totalHours > 7) if ((totalHours == 7) && (totalMins > 36)) }

Rispondi quotando