Javascript

Signaler
-
Messages postés
493
Date d'inscription
jeudi 7 juillet 2005
Statut
Membre
Dernière intervention
24 mai 2017
-
Bonjour tout le monde,
j'ai un formulaire dans lequel j'ai un champ date qui me propose un calendrier. Dès que je choisis une date il me le met au format jj/mm/yyyy et quand je valide mon formulaire j'ai accès à la page suivante.
Par contre quand je décide de taper la date moi meme et que je le mets au format jj-mm-yyyy je n'arrive pas à accéder à la page suivante; il m'affiche un message d'erreur! quelqu'un peut t'il m'aider svp?!c'est urgent
merci!

code:
<SCRIPT language= "JavaScript">
<!-- var _field = new Object();
var _today = new Date();
var _day = _today.getDate();
var _month = _today.getMonth();
var _year = century(_today.getYear());
var _firstDay = 0
var _format = "dd/MM/yyyy"
function leadingZeros(number, len) { var retVal "" + number; while (retVal.length < len) { retVal "0" + retVal; } return retVal; }
function century(number) { return (number - 0 < 1000) ? number - 0 + 1900 : number; }
function restart() { /* _field.value '' + leadingZeros(_day, 2) + '.' + leadingZeros(_month - 0 + 1, 2) + '.' + century(_year); */ _field.value formatDate(); calWindow.close(); }
function openCalendarPicker(field) { _field = field; if (_field.value.length > 0) parseDate(_field.value); calWindow=open('','myname','resizable=no,width=230,height=255, left=170, top=230'); calDocument = calWindow.document; if(_year < 200) _year+=1900; Calendar(_month,_year); calWindow.focus(); }
function Calendar(month,year) { monthName new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); dayName new Array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); var today = new Date(); var currentMonth = today.getMonth(); var currentYear = today.getYear(); var currentDay = today.getDate(); var startDate = new Date(year,month,1); var startDay = startDate.getDay(); var style = ""; if(currentYear < 200) currentYear+=1900; if((startDay-_firstDay) < 0) startDay = 7-_firstDay; else startDay = startDay-_firstDay; var stopDay = 31; if(month==3 ||month==5 || month==8 || month==10 ) --stopDay; if(month==1) { stopDay-=3; if(year%4==0) stopDay++; if(year%100==0) stopDay--; if(year%400==0) stopDay++; } calDocument.write('<title>Calendar</title>'); calDocument.write('<link rel=stylesheet type="text/css" href="../common/calendar.css">'); calDocument.write(' ' ); calDocument.write("\"); writeHeader(month,year); var dayCount = 1; for(i=0;i<=5;i++) { calDocument.write(\"----
"); for(j=0;j<=6;j++) { if((i==0)&&(j < startDay)) writeCell("", true, ""); else { if(dayCount > stopDay) writeCell("", true, ""); else { style = ""; if((year==currentYear)&&(month==currentMonth)&&(dayCount==currentDay)) style="today"; else if ((j==(7-_firstDay)) || ((_firstDay==0)&&(j==0))) style="sunday"; writeCell(dayCount, true, style); dayCount++; } } } calDocument.write(""); } calDocument.write("
"); calDocument.write(" "); calDocument.close(); }
function writeHeader(month,year) { calDocument.write("<tr>"); calDocument.write('<td class ="header" align="center" COLSPAN="7" VALIGN="middle">'); calDocument.write('<FORM NAME="Calendar">'); calDocument.write('<SELECT NAME="monthSelect" onChange="opener.changeMonth();">'); for (i=0; i<12; i++) { if (i == month) calDocument.write('<OPTION VALUE="' + i + '" SELECTED>' + monthName[i] + '</OPTION>'); else calDocument.write('<OPTION VALUE="' + i + '">' + monthName[i] + '</OPTION>'); } calDocument.write('</SELECT>'); calDocument.write(' '); calDocument.write('<SELECT NAME="yearSelect" size="1" type="select-one" onChange="opener.changeYear();">'); for (i=year-20; i<year-(-10); i++) { if (i == year) calDocument.write('<OPTION VALUE="' + i + '" SELECTED>' + i + '</OPTION>'); else calDocument.write('<OPTION VALUE="' + i + '">' + i + '</OPTION>'); } calDocument.write('</SELECT>'); calDocument.write(' " onClick="opener.changeYearPlus();"/> '); calDocument.write("</td>"); calDocument.write("</tr>"); calDocument.write("<tr>"); for(i=_firstDay;i<=6;i++) writeCell(dayName[i],false, "header"); for(i=0;i<=_firstDay-1;i++) writeCell(dayName[i],false, "header"); calDocument.write("</tr>"); }
function writeCell(content, asLink, style) { if (style !"") style "class=" + '"' + style + '"'; if (asLink) calDocument.write("<td " + style + " align=right valign=middle>"); else calDocument.write("<td " + style + " align=center valign=middle>"); if (asLink) calDocument.write('[javascript:opener.changeDay(' + content + ') ' + content + ']'); else calDocument.write(content); } function changeMonth() { _month = calDocument.Calendar.monthSelect.options[calDocument.Calendar.monthSelect.options.selectedIndex].value + ''; Calendar(_month,_year); }
function changeYear() { _year = calDocument.Calendar.yearSelect.options[calDocument.Calendar.yearSelect.selectedIndex].value + ''; Calendar(_month,_year); }
function changeDay(paramDay) { _day = paramDay + ''; restart(); self.close; }
function changeYearMinus() { _year calDocument.Calendar.yearSelect.options[calDocument.Calendar.yearSelect.selectedIndex].value + ''; _year _year - 10; Calendar(_month,_year); }
function changeYearPlus() { _year calDocument.Calendar.yearSelect.options[calDocument.Calendar.yearSelect.selectedIndex].value + ''; _year _year - 10; _year = _year + 20; Calendar(_month,_year); }
function formatDate() { var retVal=""; var i=0; var lenSub = 0; var actChar; while(i < _format.length) { actChar = _format.charAt(i); if ((actChar != "d") && (actChar != "M") && (actChar != "y")) { retVal = retVal + actChar; } else { if ((actChar != _format.charAt(i+1)) || ( (i+1) == _format.length)) { if (actChar == "d") retVal = retVal + leadingZeros(_day, lenSub + 1); if (actChar == "M") retVal = retVal + leadingZeros(_month - 0 + 1, lenSub + 1); if (actChar == "y") retVal = retVal + century(_year); lenSub = 0; } else { lenSub++; } } i++; } return retVal; }
function parseDate(parseString) { var i=0; var lenSub = 0; var actChar = ""; var typeChar = ""; var value = 0; while(i < _format.length) { actChar = _format.charAt(i); if ( ((actChar != "d") && (actChar != "M") && (actChar != "y")) || (i == _format.length-1) ) { index = parseString.indexOf(actChar); if (index < 0) index = parseString.length; value = parseString.substr(0,index); parseString = parseString.substr(index + 1, parseString.length - index); if (typeChar == "d") _day = value; if (typeChar == "M") _month = value - 1; if (typeChar == "y") _year = century(value); } else { typeChar = actChar; } i++; } if(_day<1||_day>31||_month<1||_month>12||_year<1900){ _day = _today.getDate(); _month = _today.getMonth(); _year = century(_today.getYear()); } }
-->
</SCRIPT>

1 réponse

Messages postés
493
Date d'inscription
jeudi 7 juillet 2005
Statut
Membre
Dernière intervention
24 mai 2017
3
Salut, et si tu le tapes dans c'est formats :
yyyy/dd/mm, yyyy/mm/dd, yyyy-mm-jj ou yyyy-jj-mm, etc

Tu auras aussi un problème ?
Donc, je ne crois pas que c'est ton calendrier qui stop l'accès car bien sûr, avant de cliquer sur "envoyer", il n' y a aucun bogue.
Donc, c'est après le submit ?
Quel est le message d'erreur ?

stéph