Salve,
Ho provato a fare una ricerca nel forum e, pur avendo trovato diverse risposte attinenti al mio caso, nessuna di queste presenta il mio stesso grado di complessità...
In breve: su un pulsante type="Button" ho inserito (con Dreamweaver ed alcune sue estensioni) sia la validazione dei campi che l'invio del form, e fin qui in effetti non ci sono problemi: il form viene inviato senza problemi
Le grane nascono quando, oltre alla validazione ed al submit, vorrei disabilitare il pulsante in modo che non venga cliccato due volte... ho usato this.disabled=true provandolo a mettere nelle posizioni più disparate, ma non sono riuscito a cavare un ragno dal buco...
Posto il codice:
FUNZIONI:
PULSANTE:codice:function WAtrimIt(theString,leaveLeft,leaveRight) { if (!leaveLeft) { while (theString.charAt(0) == " ") theString = theString.substring(1); } if (!leaveRight) { while (theString.charAt(theString.length-1) == " ") theString = theString.substring(0,theString.length-1); } return theString; } function WAAddError(formElement,errorMsg,focusIt,stopIt) { if (document.WAFV_Error) { document.WAFV_Error += "\n" + errorMsg; } else { document.WAFV_Error = errorMsg; } if (!document.WAFV_InvalidArray) { document.WAFV_InvalidArray = new Array(); } document.WAFV_InvalidArray[document.WAFV_InvalidArray.length] = formElement; if (focusIt && !document.WAFV_Focus) { document.WAFV_Focus = focusIt; } if (stopIt == 1) { document.WAFV_Stop = true; } else if (stopIt == 2) { formElement.WAFV_Continue = true; } else if (stopIt == 3) { formElement.WAFV_Stop = true; formElement.WAFV_Continue = false; } } function WAValidateRQ(formElement,errorMsg,focusIt,stopIt,trimWhite,inputType) { var isValid = true; if (!document.WAFV_Stop && !formElement.WAFV_Stop) { if (inputType == "select") { if (formElement.selectedIndex == -1) { isValid = false; } else if (!formElement.options[formElement.selectedIndex].value || formElement.options[formElement.selectedIndex].value == "") { isValid = false; } } else if (inputType == "checkbox") { if (formElement.length) { isValid = false; focusIt = false; for (var x=0; x<formElement.length ; x++) { if (formElement[x].checked && formElement[x].value!="") { isValid = true; break; } } } else if (!formElement.checked) isValid = false; } else if (inputType == "radio") { isValid = false; if (formElement.checked) isValid = true; } else if (inputType == "radiogroup") { isValid = false; for (var x=0; x<formElement.length; x++) { if (formElement[x].checked && formElement[x].value!="") { isValid = true; break; } } formElement = formElement[0]; } else { var value = formElement.value; if (trimWhite) { value = WAtrimIt(value); } if (value == "") { isValid = false; } } } if (!isValid) { WAAddError(formElement,errorMsg,focusIt,stopIt); } } function WAAlertErrors(errorHead,errorFoot,setFocus,submitForm) { if (!document.WAFV_StopAlert) { document.WAFV_StopAlert = true; if (document.WAFV_InvalidArray) { document.WAFV_Stop = true; var errorMsg = document.WAFV_Error; if (errorHead!="") errorMsg = errorHead + "\n" + errorMsg; if (errorFoot!="") errorMsg += "\n" + errorFoot; document.MM_returnValue = false; if (document.WAFV_Error!="") alert(errorMsg.replace(/"/g,'"')); else if (submitForm) submitForm.submit(); if (setFocus && document.WAFV_Focus) { document.tempFocus = document.WAFV_Focus; setTimeout("document.tempFocus.focus();setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1); } else { document.WAFV_Stop = false; document.WAFV_StopAlert = false; } for (var x=0; x<document.WAFV_InvalidArray.length; x++) { document.WAFV_InvalidArray[x].WAFV_Stop = false; } } else { document.WAFV_Stop = false; document.WAFV_StopAlert = false; if (submitForm) { submitForm.submit(); } document.MM_returnValue = true; } document.WAFV_Focus = false; document.WAFV_Error = false; document.WAFV_InvalidArray = false; } } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MK_dynamicForm() { //v4.0 var obj,l,args=MK_dynamicForm.arguments; val=document.MM_returnValue; val=(val==null)?true:val; if(val){obj=MM_findObj(args[0]);l=args.length; if(obj){if(l>2){for (i=2; i<(l-1); i+=2) {eval("obj."+args[i]+"='"+args[i+1]+"';")}} eval("obj."+args[1]+"();");}} document.MM_returnValue = false; }
Mi rendo conto che le funzioni della validazione sono "lunghe" e forse eccessive, ma avendo acquistato quell'estensione per Dreamweaver mi dispiacerebbe abbandonarla a favore di qualcosa di più "manuale": insomma, dato questo codice postato prima, come faccio a disabilitare il pulsante?codice:<input name="Button" type="button" onclick="WAValidateRQ(document.form1.Nome,'* Nome obbligatorio',document.form1.Nome,0,true,'text');WAAlertErrors('','',true,false);MK_dynamicForm('form1','submit','method','post','action','pagina.htm');return document.MM_returnValue" value="Vai" />
Grazie a tutte le anime pie... :-)


Rispondi quotando