Hi John
Thanks again.
The onblur event fires fine.
This for me is an academic problem rather than a big issue, it is a 'what if' I would like to cater for.
Here is my code, the original version as opposed to the later one in which I added your suggested code.
Javascript
Code:
function fielderror(msg) {
alert(msg);
setTimeout('fieldFocus3()', 100);
return false;
}
function fieldFocus3() {
date_char=0;
jaugeage.startDate.value = "jj/mm/aaaa";
jaugeage.startDate.select();
jaugeage.startDate.focus();
return false;
}
function mondaycheck(datechosen) {
if (datechosen=="jj/mm/aaaa"){
fielderror("Veuillez écrire la date");
} else {
var dtCh= "/";
var pos1=datechosen.indexOf(dtCh);
var pos2=datechosen.indexOf(dtCh,pos1+1);
if (pos1==-1 || pos2==-1){
fielderror("Veuillez écrire la date de début comme ceci jj/mm/aaaa");
}
if (pos1!=-1 && pos2!=-1){
var parts = datechosen.split('/');
var passdate = new Date(parseFloat(parts[2]),(parseFloat(parts[1])-1),parseFloat(parts[0]),23,59,59,999);
var thisDay=passdate.getDay();
Testtoday = new Date();
if(passdate < Testtoday) {
fielderror("La date ne peut pas être plus tôt qu'aujourd'hui");
}
else {
var myDays= ["Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"];
var daychosen = myDays[thisDay];
if (daychosen != "Lundi") {
fielderror("Lundi seul");
}
else {
var mondate = new Date(passdate.valueOf());
var mody = mondate.getDate();
var monmo = mondate.getMonth()+1;
var monyr = mondate.getFullYear();
if (mody < 10){ mody = '0' + mody;}
if (monmo < 10){ monmo = '0' + monmo;}
var tuedate = new Date(passdate.valueOf() + (1 * 24 * 60 * 60 * 1000));
var tudy = tuedate.getDate();
var tuemo = tuedate.getMonth()+1;
var tueyr = tuedate.getFullYear();
if (tudy < 10){ tudy = '0' + tudy;}
if (tuemo < 10){ tuemo = '0' + tuemo;}
var weddate = new Date(passdate.valueOf() + (2 * 24 * 60 * 60 * 1000));
var wddy = weddate.getDate();
var wedmo = weddate.getMonth()+1;
var wedyr = weddate.getFullYear();
if (wddy < 10){ wddy = '0' + wddy;}
if (wedmo < 10){ wedmo = '0' + wedmo;}
var thurdate = new Date(passdate.valueOf() + (3 * 24 * 60 * 60 * 1000));
var thdy = thurdate.getDate();
var thurmo = thurdate.getMonth()+1;
var thuryr = thurdate.getFullYear();
if (thdy < 10){ thdy = '0' + thdy;}
if (thurmo < 10){ thurmo = '0' + thurmo;}
var fridate = new Date(passdate.valueOf() + (4 * 24 * 60 * 60 * 1000));
var frdy = fridate.getDate();
var frimo = fridate.getMonth()+1;
var friyr = fridate.getFullYear();
if (frdy < 10){ frdy = '0' + frdy;}
if (frimo < 10){ frimo = '0' + frimo;}
/* document.getElementById('beginDate').innerHTML = mody+"/"+monmo+"/"+monyr;
document.getElementById('beginDateField').value = mody+"/"+monmo+"/"+monyr;
document.getElementById('endDate').innerHTML = frdy+"/"+frimo+"/"+friyr;
document.getElementById('FridayDate').innerHTML = frdy+"/"+frimo+"/"+friyr;
document.getElementById('endDateField').value = frdy+"/"+frimo+"/"+friyr;
document.getElementById('thursDate').innerHTML = thdy+"/"+thurmo+"/"+thuryr;
document.getElementById('thursDateField').value = thdy+"/"+thurmo+"/"+thuryr;
document.getElementById('wedsDate').innerHTML = wddy+"/"+wedmo+"/"+wedyr;
document.getElementById('wedsDateField').value = wddy+"/"+wedmo+"/"+wedyr;
document.getElementById('tuesDate').innerHTML = tudy+"/"+tuemo+"/"+tueyr;
document.getElementById('tuesDateField').value = tudy+"/"+tuemo+"/"+tueyr;
return true;*/
}
}
}
}
}
var date_char=0;
function mask(str,textbox,loc,delim){
if (date_char>7){
date_char=0;
str="";
textbox.value="";
} else if (date_char==0){
str="";
textbox.value="";
}
var masklocs = loc.split(',');
for (var i = 0; i <= masklocs.length; i++){
for (var k = 0; k <= str.length; k++){
if (k == masklocs[i]){
if (str.substring(k, k+1) != delim){
if (event.keyCode != 8){ //backspace
str = str.substring(0,k) + delim + str.substring(k,str.length);
}
}
}
}
}
if (event.keyCode != 37 && event.keyCode != 39 && event.keyCode != 46) {
textbox.value = str;
}
date_char=date_char+1;
}
and here is the HTML input line
HTML Code:
<td align="center"><b><i>PREVISIONS DE JAUGEAGE SEMAINE DU </i></b>
<input type="text" size="12" value="jj/mm/aaaa" maxlength="12" name="startDate" tabindex="2" onKeyDown="if(event.keyCode==13) event.keyCode=9;" onKeypress="javascript:return mask(this.value,this,'2,5','/');" onblur="mondaycheck(this.value);"/>
</td>
If you try this you will see that all functions fire as expected, I have fitted your code into the functions but the 'event' does not detect the Tab using onblur.
I put the code to detect which key was pressed at the start of the mondaycheck() function and tested it, it came back as undefined.
If the enter key is pressed rather than the Tab then focus is returned as expected to the startDate field.
If there is another input field following startDate then focus 'flicks' to that before returning to startDate, this is because of the setTimeout.
So the issue only occurs when it is the Tab key used and there is no further input field.
I'm curious as to why this occurs
Bookmarks