View Full Version : But it really is false

02-22-2007, 01:23 PM
I have a validation function which compares two values, startsecs and endsecs. If startsecs is greater than endsecs, an error should be displayed, but it's not working because the if statement is evaluating as true, when it should be false.

You can see this by going to link removed, uncheck the box that says 'this event last all day', then enter 12:00 as the start time and 17:00 as the end time, and click save. Evevn in the error that's displayed, the second value is greater than the first, so it should evaluate as false.

The function can be seen at link removed on line 223.

var startsecs = (document.getElementById('starthour').value * 60) + document.getElementById('startminute').value;
var endsecs = (document.getElementById('endhour').value * 60) + document.getElementById('endminute').value;
if(startsecs > endsecs) {
document.getElementById('error_end').innerHTML = 'End time must be after start time:'+endsecs+'::'+startsecs;
document.getElementById('error_end').style.display = 'block';
valid = false;

02-22-2007, 03:10 PM
Anytime you're using a .value of something as a number, you need a parseInt or parseFloat. Otherwise, it's text and you get fun results with things.

02-22-2007, 03:42 PM
Problem solved. Thanks for the help.

For anyone that's interested, I needed to multiple the second .value by 1, which forced it's type to an integer.