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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting JavaScript to work in IE 1

Status
Not open for further replies.

peacecodotnet

Programmer
May 17, 2004
123
0
0
US
This is a possible doctype problem...or maybe I just suck at coding JavaScript.

Here is the page in question:

I'm making an Emailer for myself with PHP, but before the form gets submitted I want a JavaScript just to make sure that all fields have been filled in (the date fields don't need to be filled in, but if one of the date fields is filled in all must be filled in).

The JavaScript that I have there now works alright in FireFox, but it does nothing in IE. It is supposed to check whether everything is filled. If something is not filled, that error gets added to the variable 'errorstr' and at the end a <span>'s innerHTML is set to errorstr. If there were any errors on the form submit, it returns false so the form doesn't submit.

I can't figure out why it doesn't work in IE. Could it be that I need some type of doctype?

Any help would be greatly appreciated.

Peace out,
Peace Co.
 

It's not a DOCTYPE issue at all, but just using shortcut methods that are really bad programming practice.

Instead of referring to the ids of your elements, like this:

Code:
stuff = TO.value.length;

you should be using getElementById instead:

Code:
stuff = document.getElementById('TO').value.length;

If you use this method whereever you are accessing elements by their ids, you should be fine.

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Thanks a lot! This looks very promising. This is the kind of stuff that I just don't know...because I usually don't do JavaScript.

Thanks again.

Peace out,
Peace Co.
 

Incidentally, I was not only talking about that syntax for form elements, but all elements - including the ones you write your error data into.

While the error data does display in IE with the shortcut method (oddly enough), it is not something that should be encouraged. For maximum compatibility, you should use the getElementById method everytime you need to access any element by its id.

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top