ehehehe... ragazzo mio...
ma io l'avevo gia fatta quella prova: se il focus lo sposto da un altra parte e poi premo invio, parte il submit (come mi aspetto che faccia)
i browser con cui faccio la prova l'avevo gia scritto sopra (IE,FF e Opera)
per quanto riguarda tutto il codice... beh... per me non ci sono problemi a postare tutto... ma è davvero tanta roba... tanti file... non so quale parte possa essere "incriminata"...
e dubito che qualcuno abbia la voglia di mettersi a vedere migliaia di righe di codice...
magari posto due file a cui do piu "importanza":
1° file (che viene invocato alla pressione del tasto submit, che pensa a controllare l'effettiva presenza di dati. Se tutto ok apre un'altra pagina che provvede all'inserimento effettivo dei dati nel database Oracle)
codice:
var test;
function Modulo(theform) {
var az=document.form1.selectazienda.selectedIndex;
var sede=document.form1.sede.selectedIndex;
var data=document.form1.textfielddata.value;
var docrif=document.form1.docrif.value;
var tempmin=document.form1.tempmin.value;
var tempmax=document.form1.tempmax.value;
if ((sede=="")||(sede=="undefined")) {
alert ("Scegliere una sede di accettazione");
document.form1.sede.focus();
return false;
}
else if((az=="")||(az=="undefined")){
alert("Cercare e selezionare un'azienda");
document.form1.selectazienda.focus();
return false;}
else if((docrif=="")||(docrif=="undefined")){
alert("Inserire Documento di Riferimento");
document.form1.docrif.focus();
return false;}
else if((tempmin=="")||(tempmin=="undefined")){
alert("Inserire Temperatura minima");
document.form1.tempmin.focus();
return false;}
else if((tempmax=="")||(tempmax=="undefined")){
alert("Inserire Temperatura massima");
document.form1.tempmax.focus();
return false;}
else if ((data=="")||(document.all['textfielddata'].style.color != '#008000')&&(document.all['textfielddata'].style.color != 'rgb(0, 128, 0)')) {
alert ("Inserisci una data valida");
document.form1.textfielddata.focus();
return false;
}
var a = 350; // LARGHEZZA NUOVA FINESTRA
var b = 100; // ALTEZZA NUOVA FINESTRA
var w = screen.width;
var h = screen.height;
var sx= ((w-a)/2);
var su = (((h-b)/2)-50);
var parametri = "width="+a+",height="+b+",left="+sx+",top="+su+",resizable=1";
s = document.all['inviadatabase'].disabled=true;
p = window.open('inserimento.php?'+'textfielddata='+document.all.textfielddata.value+'&selectazienda='+document.form1.selectazienda.value+'&sede='+document.form1.sede.value+'&annoreg='+document.form1.annoreg.value+'&docrif='+document.form1.docrif.value+'&tempmin='+document.form1.tempmin.value+'&tempmax='+document.form1.tempmax.value,"Inserimento",parametri);
try {
p.close();
}
catch (e) {
document.getElementById('checkpopup').style.display='block';
}
wind=window.open('inserimento.php?'+'textfielddata='+document.all.textfielddata.value+'&selectazienda='+document.form1.selectazienda.value+'&sede='+document.form1.sede.value+'&annoreg='+document.form1.annoreg.value+'&docrif='+document.form1.docrif.value+'&tempmin='+document.form1.tempmin.value+'&tempmax='+document.form1.tempmax.value,"Inserimento",parametri);
return false;
}
2° file - Intercetta i tasti premuti per trasformare la data da formato numerico a formato testuale (da Pietro09)
(magari puo dar fastidio in qualche modo...)
codice:
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
/*---------------------------------------------------------------------
Questa funzione accetta una variabile stringa e verifica se e una data.
La data deve essere nel formato giorno mese anno. Il giorno e il mese
devono essere di 1 o 2 cifre, l'anno deve essere di 2 o 4 cifre.
Il delimitatore deve essere / o - o .
Restituisce un oggetto con le proprieta:
.isdate = vero o falso
.error = messaggio errore
.year = anno
.month = mese (1 - 12)
.monthname = Gennaio - Dicembre
.day = giorno (1 - 31)
.data = oggetto data
---------------------------------------------------------------------*/
function isdate(dateStr)
{
var ret = new Object();
ret.isdate = false;
ret.error = "";
ret.year = 0;
ret.month = 0;
ret.monthname = "";
ret.day = 0;
ret.data = null;
// inizio stringa
// 1 o 2 cifre
// / o - o .
// 1 o 2 cifre
// / o - o .
// 4 cifre
// fine stringa
//var datePat = /^(\d{1,2})(\/|-|.)(\d{1,2})(\/|-|.)(\d{4})$/;
//var datePat = /^\s*(\d{1,2})(\/|-|\.)(\d{1,2})(\2)(\d{2}|\d{4})\s*$/;
var datePat = /^\s*(\d{1,2})(\/|-|\.)(\d{1,2})(\2)(\d{4})\s*$/;
//restituisce, allo stesso modo di una matrice, i risultati di una ricerca
//di una stringa utilizzando un oggetto Regular Expression
var matchArray = dateStr.match(datePat);
if (matchArray == null) {
ret.error = "Per favore, introduci la data nei formati gg/mm/aaaa o gg-mm-aaaa o gg.mm.aaaa";
return ret;
}
day = matchArray[1];
month = matchArray[3];
year = matchArray[5];
if(year.length == 2)
if(parseInt(year,10) < 30)
year = parseInt(year,10) + 2000;
else
year = parseInt(year,10) + 1900;
if (month < 1 || month > 12) { // il mese deve essere compreso tra 1 e 12
ret.error = "Il mese deve essere compreso tra 1 e 12.";
return ret;
}
if (day < 1 || day > 31) {//il giorno non puo essere < 1 e > 31
ret.error = "Il giorno deve essere compreso tra 1 e 31";
return ret;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//i mesi aprile, giugno, settembre, novembre, hanno 30 giorni
ret.error = "Il mese " + month + " non ha 31 giorni!";
return ret;
}
if (month == 2) { // verifica se l'anno e bisestile: febbraio puo avere 29 giorni
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
ret.error = "Febbraio " + year + " non ha " + day + " giorni!";
return ret;
}
}
isDateError = "";
// se sono qui, la data e valida!
ret.isdate = true;
ret.error = "";
ret.year = year;
ret.month = month;
ret.day = day;
ret.data = new Date(year, (month - 1), day);
switch(parseInt(month,10))
{
case 1: ret.monthname = "Gennaio"; break;
case 2: ret.monthname = "Febbraio"; break;
case 3: ret.monthname = "Marzo"; break;
case 4: ret.monthname = "Aprile"; break;
case 5: ret.monthname = "Maggio"; break;
case 6: ret.monthname = "Giugno"; break;
case 7: ret.monthname = "Luglio"; break;
case 8: ret.monthname = "Agosto"; break;
case 9: ret.monthname = "Settembre"; break;
case 10: ret.monthname = "Ottobre"; break;
case 11: ret.monthname = "Novembre"; break;
case 12: ret.monthname = "Dicembre"; break;
default: ret.monthname = ""; break;
}
return ret;
}
//------------------------------------------------
//valida la stringa dateStr
//------------------------------------------------
function IsDate(dateStr)
{
var datePat = /^((3[01]|[12]\d|0?[1-9])\/(0?[13578]|10|12)\/(\d\d)?\d\d|(30|[12]\d|0?[1-9])\/(0?[469]|11)\/(\d\d)?\d\d|(2[0-8]|[01]\d|0?[1-9])\/(0?2)\/(\d\d)?\d\d|29\/(0?2)\/(1200|1600|2000|2400|2800|00)|29\/(0?2)\/(\d\d)?(0[48]|[2468][048]|[13579][26]))$/;
var matchArray = dateStr.match(datePat);
return !(matchArray == null);
}
document.onkeypress = document_onkeypress;
function document_onkeypress(e)
{
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
var target = (e.target)?e.target:e.srcElement;
var id = target.id;
var CorrenteSeparatoreDecimale = '.'.charCodeAt(0);
//integer
if(id == "text1" || id == "_txt_data_documento" || id == "txt_data_protocollo_industra")
{
if ( !((code >= 48 && code <= 57 ) || code == 8 || code == 37 || code == 39 || code == 36 || code == 35 || code == 13) )
{
if (window.event)
{
e.returnValue = false;
e.cancelBubble;
}
else
{
if(e.preventDefault) e.preventDefault;
return false;
}
}
}
//float
else if(id == "text2" || id == "_txt_data_documento" || id == "txt_data_protocollo_industra")
{
if ( !((code >= 48 && code <= 57 ) || code == CorrenteSeparatoreDecimale || code == 8 || code == 37 || code == 39 || code == 36 || code == 35 || code == 13) )
{
if (window.event)
{
e.returnValue = false;
e.cancelBubble;
}
else
{
if(e.preventDefault) e.preventDefault;
return false;
}
}
}
//data
else if(id == "Text1" || id == "_txt_data_documento" || id == "txt_data_protocollo_industra")
{
if ( !((code >= 48 && code <= 57 ) || code == 47 || code == 8 || code == 37 || code == 39 || code == 36 || code == 35 || code == 45 || code == 46 || code == 13) )
{
if (window.event)
{
e.returnValue = false;
e.cancelBubble;
}
else
{
if(e.preventDefault) e.preventDefault;
return false;
}
}
else
{
if(id == "Text1")
window.setTimeout(function(){ controllaData.call(target); }, 1);
}
}
//sostituzione del codice digitato
else if(id == "text4" || id == "_txt_data_documento" || id == "txt_data_protocollo_industra")
{
if(code == 46)
{
if (window.event)
{
e.returnValue = false;
e.cancelBubble;
}
else
{
var newEvent = document.createEvent("KeyEvents");
newEvent.initKeyEvent("keypress", true, true, document.defaultView, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 0, "*".charCodeAt(0)) ;
if(e.preventDefault) e.preventDefault();
target.dispatchEvent(newEvent);
return false;
}
}
}
}
window.onload = window_onload;
function window_onload()
{
var d = $("Text1");
d.focus();
}
function controllaData()
{
//$("div1").innerHTML = this.value;
var d = this.value;
var ret = isdate(d);
if(!ret.isdate)
{
this.style.color = "red";
}
else
{
this.style.color = '#008000';
this.value = ret.day + " " + ret.monthname + " " + ret.year;
}
}