Buongiorno a tutti, ho la necessità di modificare il formato data da un file html contenente javascript. La data in origine è espressa nel formato gg/mm/aa ed io la devo modificare in gg/mm/aaaa. Ho cercato nel codice i parametri che fanno riferimento alla data, sia per la parte javascript che per il form in html, ma l'unico risultato che ho ottenuto finora è quello di non far funzionare più nulla. Per intenderci io ho modificato (aumentando i valori numerici) le righe 57 104 del codice che vedete sotto. Qualcuno sa dirmi dove ho sbagliato? Grazie.
codice HTML:
<head><style type="text/css">span.errors {color:red;font-weight:bold}span.result {color:grey;}</style><script language="javascript">
charmap ="ABC0DEF1-GHI2JKL3M%NO4PQ5RS6TU!7VWX8YZ9";// 0123456789012345678901234567890123456// 1 2 3 shiftValue=10; function calcolaCodice() { maxLenghtName=20; maxLenghtSurname=20; document.getElementById("errorName").innerHTML = ''; document.getElementById("errorSurname").innerHTML = ''; document.getElementById("errorDate").innerHTML = ''; document.getElementById("customerCode").innerHTML = ''; surname = document.INFO.surname.value; name = document.INFO.name.value; date=document.INFO.date.value //remove starting and endig spaces name=name.replace(/^\s*/, "").replace(/\s*$/, ""); surname= surname.replace(/^\s*/, "").replace(/\s*$/, ""); date=date.replace(/\//g,"") if (name == "" ) { document.getElementById("errorName").innerHTML = 'Nome vuoto!'; return; } if (name.length > maxLenghtName) { document.getElementById("errorName").innerHTML = 'La lunghezza del nome scelto ('+name.length+' caratteri), supera il massimo consentito di '+maxLenghtName+ ' caratteri.'; return; } if (!name.match(/^[A-Za-z\'\ ]*$/)) { document.getElementById("errorName").innerHTML = 'Nome invalido. Sono validi solo i caratteri, lo spazio e l\'apostrofo.'; return; }
if (surname == "" ) { document.getElementById("errorSurname").innerHTML = 'Cognome vuoto!'; return; } if (surname.length > maxLenghtSurname) { document.getElementById("errorSurname").innerHTML = 'La lunghezza del nome scelto ('+surname.length+' caratteri), supera il massimo consentito di '+maxLenghtSurname+ ' caratteri.'; return; } if (!surname.match(/^[A-Za-z\'\ ]*$/)) { document.getElementById("errorSurname").innerHTML = 'Cognome invalido. Sono validi solo i caratteri, lo spazio e l\'apostrofo.'; return; } if (!date.match(/^[0-9]*$/) || date.length !=6) { document.getElementById("errorDate").innerHTML = 'Data invalida: sono ammessi solo numeri, la data deve essere nel formato gg/mm/aa. es: 03/12/81'; } surname=surname.replace(/\'/g,"%"); surname=surname.replace(/\ /g,"!"); customerCode=trasla(surname+'-'+date,shiftValue); document.getElementById("customerCode").innerHTML = '<b>Codice utente: </b>'+name+'-'+customerCode; //document.getElementById("account").innerHTML = code2name(customerCode)}
function trasla(string, shift) { string = string.toUpperCase(); array=string.split(""); result=""; for ( k=array.length-1; k>-1; k--) { index=charmap.indexOf(array[k])+shift; if (index>charmap.length-1) { index=index-charmap.length; } else if (index<0) { index=charmap.length+index; } result+=charmap.substr(index,1); } return result.toLowerCase();}
</script>
</head>
<body><div id="Name2Cod"> <form name="INFO"> Nome:<br/> <input type="text" name="name" value="" size=30 maxlength=30></input> <span id="errorName" class="errors" ></span> <br/> Cognome:<br/> <input type="text" name="surname" value="" size=30 maxlength=30> <span id="errorSurname" class="errors" ></span> <br/> Data di nascita: (formato: gg/mm/aa)<br/> <input type="text" name="date" value="" size=8 maxlength=8> <span id="errorDate" class="errors" ></span> <br/> <input type="button" value="CALCOLA" onClick="calcolaCodice()"> </form> <br/> <span class="result" id="customerCode"></span> <br/> </div><div id="Cod2Name"></div>
</body>