Hi all!

I am trying to get a JavaScript date selector to work for a front end I'm writing. I've seen a lot of problems related to JavaScript and IE vs. Firefox but I've yet to find a solution to my issue.

I have a simple form - when you click on the calendar image the calendar should pop up and allow you to select the date. IE invokes the javascript page and brings up the calendar just fine, but when I try the same in Firefox it doesn't work.

I eliminated all the extraneous stuff from my page - leaving just the input box and calendar selection - and still it works in IE and not Firefox. Here's that code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>
<head>
	<title>Service statistics search</title>
	<script type="text/javascript" src="datetimepicker_css.js"></script>
</head>

<body>

<table>
	<input id="startdate" type="text" size="12">
	<a href="javascript:NewCssCal('startdate','yyyymmdd')">
	<img src="images/cal.gif" width="17" height="17" alt="Pick a start date"></a>
</table>
</body>

From the error console:
Error: NewCssCal is not defined
Source File: javascript:NewCssCal('startdate','yyyymmdd')
Line: 1

The calendar I'm using is from here:http://www.rainforestnet.com/datetimepicker.htm. I placed the test page they provided on my server - the same problem exists there too.

It seems that it just plain doesn't want to load the JavaScript page. Any ideas as to why? There must be something I'm missing or doing wrong.

Recommended Answers

All 6 Replies

Brandi,

It seems that FF doesn't like that form of javascript URL.

I have seen "javascript<b></b>" before but have no idea where it comes from. As far as I know the <b></b> has no place in there but would like to know why there are so many examples of it floating around (mostly in forum topics about stuff that's not working!).

Try either of these:

<a href="javascript:NewCssCal('startdate','yyyymmdd')"><img src="images/cal.gif" width="17" height="17" alt="Pick a start date"></a>

<a href="" onclick="NewCssCal('startdate','yyyymmdd'); return false"><img src="images/cal.gif" width="17" height="17" alt="Pick a start date"></a>

In my book, the second is definately preferred. Javascript urls are very last millennium.

Airshow

Hmm...I tried both of your examples, Airshow, with no success. Thanks for your response. :)

They have examples on their site of the calendar that work with Firefox, but I don't see anything obvious in their source code that's different than mine.

I'm by no stretch a web programming expert, but there must be some sort of way to get this thing to work without forcing my users to only use IE, or pasting the javascript code for the calendar directly into my html page (even if that would work there's a lot, it'd be ugly).

Ah, well, I will try and find another solution but if anyone has any other suggestions in the meantime it is muchly appreciated.

Brandi,

Those two examples of mine work fine in FF 3.0.11 . I think the problem must have been with the original calendar.

Do you know how to see the javascript error console in FF?
"Tools" > "Error console".

It gives you a line number to indicate where the code breaks down.

IE gives pop up messages (there's also a plugin to make things half decent). I can't remember what Opera does - similar to IE I think.

Airshow

Saving myself some effort and grief, I just decided to use something different and a little simpler. This *does* work with my code.

http://www.mattkruse.com/javascript/calendarpopup/

FYI: the problem with the original script is the form needs both ID and NAME for the JS to find it.

<input id="startdate" name="startdate" type="text" size="12">

-[g]

probably giffen is right

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.