As part of data entry I am checking the validity of a date field and using the onchange event to trigger the check. As you will note it also compares start and end dates, but that's not the issue. The issue is that after a bad date is detected and the alert pops up as it should, but the focus does not return to the violating field. I don't understand why. Please let me know if you have an explanation and/or fix. thanks.

David

The php code looks like this:
[php
<input id="date-due" name="goal_due" onchange="compare_goaldates(this); type="text" value="<?php echo '$goaldeadline' ?>"/>
]

[javascript
function compare_goaldates(fld){
var sdate= document.getElementById.value;
var edate= document.getElementById.value;

var retval = compareDates(sdate, edate);

if (retval == 99){
alert('Invalid date!');
fld.focus();
return false;
}
/* more stuff below*/
]

Try a time delay after the alert.

Try a time delay after the alert.

It didn't make any difference, independent of the delay.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.