We help IT Professionals succeed at work.
Get Started

mozilla firefox and google chrome differences in javascript new Date(); functionality 0o

648 Views
Last Modified: 2012-05-12
hi there,
i am using the following javascript to currently create two date objects and compare them, this works in firefox from version 3.0+ atm.
html elements inspected after ajax population in firebug 1.8.3 within firefox 7.0.1:
<select tabindex="10" accesskey="i" id="menu_fromtimestamp" name="menu_fromtimestamp">
          <option>* Select Month From</option>
          <option value="2011-08-01 00:00:00">1st August 2011, 00:00:00</option>
          <option value="2011-09-01 00:00:00">1st September 2011, 00:00:00</option>
          <option value="2011-10-01 00:00:00">1st October 2011, 00:00:00</option>
          <option value="2011-11-01 00:00:00">1st November 2011, 00:00:00</option>
</select>
<select tabindex="11" accesskey="m" id="menu_totimestamp" name="menu_totimestamp">
          <option>* Select Month To</option>
          <option value="2011-11-30 23:59:59">30th November 2011, 23:59:59</option>
          <option value="2011-10-31 23:59:59">31st October 2011, 23:59:59</option>
          <option value="2011-09-30 23:59:59">30th September 2011, 23:59:59</option>
          <option value="2011-08-31 23:59:59">31st August 2011, 23:59:59</option>
</select>

Open in new window

onchange functions for these two elements:
document.form_transactions.menu_fromtimestamp.onchange = function () {
	var fi = document.form_transactions.menu_fromtimestamp.selectedIndex;
	var ti = document.form_transactions.menu_totimestamp.selectedIndex;
	var from = document.form_transactions.menu_fromtimestamp.options[fi].value;
	var till = document.form_transactions.menu_totimestamp.options[ti].value;
	var fm = document.form_transactions.menu_fromtimestamp.options[fi].text.split(" ")[1];
	var tm = document.form_transactions.menu_totimestamp.options[ti].text.split(" ")[1];
	var fd = new Date(
			  	fm + " " +					// month
				from.split("-")[2] + ", " +		// dd,
				from.split("-")[0]				// yyyy
			 );
	var td = new Date(
			  	tm + " " +					// month
				till.split("-")[2] + ", " +		// dd,
				till.split("-")[0]				// yyyy
			 );
	if (td > fd) {
		return ajaxRequest(document.form_transactions.button_refresh);
	} else {
		alert("The TO date must be after the FROM date!"); return false;
	}
}
document.form_transactions.menu_totimestamp.onchange = function () {
	var fi = document.form_transactions.menu_fromtimestamp.selectedIndex;
	var ti = document.form_transactions.menu_totimestamp.selectedIndex;
	var from = document.form_transactions.menu_fromtimestamp.options[fi].value;
	var till = document.form_transactions.menu_totimestamp.options[ti].value;
	var fm = document.form_transactions.menu_fromtimestamp.options[fi].text.split(" ")[1];
	var tm = document.form_transactions.menu_totimestamp.options[ti].text.split(" ")[1];
	var fd = new Date(
			  	fm + " " +					// month
				from.split("-")[2] + ", " +		// dd,
				from.split("-")[0]				// yyyy
			 );
	var td = new Date(
			  	tm + " " +					// month
				till.split("-")[2] + ", " +		// dd,
				till.split("-")[0]				// yyyy
			 );
	if (td > fd) {
		return ajaxRequest(document.form_transactions.button_refresh);
	} else {
		alert("The TO date must be after the FROM date!"); return false;
	}
}

Open in new window

now when selecting From 1st October, in firefox it works no problem no matter the version.
in google chrome however - it does not work! there is clearly some difference. the result is that it alerts one of these dates created, selected 1st October for From and 30th November for To, it says you can't select From date that is after the To date! :(
how the heck would i have to create these dates to compare, so that these functions are compatible for both Mozilla Firefox and Google Chrome?
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE