Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function for onsubmit works in chrome not in safari

Status
Not open for further replies.

jackz15

Programmer
Jun 28, 2006
103
US
I have the following function run onsubmit for a form:
Code:
function validate(form)
{

for(i = 0; i < form.elements.length; i++)
{
if(form.elements[i].value == "") {
alert('Please fill everything!');
return false;
}
}
if(form.AP1.value=='PM' && form.hour.value !='00' && form.hour.value !='12'){
		b_time=form.hour.value*1;
		b_time=b_time+12;
		
}else{
b_time=form.hour.value;	
}
if(form.AP2.value=='PM' && form.hour2.value !='00' && form.hour2.value !='12'){
		b2_time=form.hour2.value*1;
		b2_time=b2_time+12;
		
}else{
	b2_time=form.hour2.value;	
}
begin=form.date.value+" "+b_time+":"+form.min.value+":00";
end=form.date_end.value+" "+b2_time+":"+form.min2.value+":00";

var myDate = new Date(begin); // Your timezone!
var myEpoch = myDate.getTime()/1000.0;

var myDate1 = new Date(end); // Your timezone!
var myEpoch1 = myDate1.getTime()/1000.0;
if(myEpoch1>=myEpoch){


}else{
	alert('Please make sure your end time is after start time! Midnite is the first hour of each day!');
return false;	
}
return true;
}

basically it checks that everything is filled and that the epoch time of ending date for the event is greater than the starting date. This works fine in chrome, but why does it not work in safari? Could some one lend me a hand?
 
Perhaps you can tell us how its not working in Safari?

Does it not issue alerts?

And show us you form code too please.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
As Phil says, we need to know how it isn't working in Safari and also to see your form code.

I put together a simple test harness which worked for me insofar as the alerts behaved as expected, although admittedly, I did change this:

Code:
if(myEpoch1 >= myEpoch) {
} else {
	alert('Please make sure your end time is after start time! Midnite is the first hour of each day!');
	return false;    
}

to this:

Code:
if(myEpoch1 <= myEpoch) {
	alert('Please make sure your end time is after start time! Midnight is the first hour of each day!');
	return false;
} else {
}

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top