wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Cross browser issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Cross browser issues" Watch "Cross browser issues" New topic
Author

Cross browser issues

kat luna
Greenhorn

Joined: Jul 20, 2001
Posts: 16
Can anyone point me to a good resource for writing javascript that functions in both IE and Netscape version 4 and up? I have studied documents and tutorials until I'm half blind, but even the simplest code seems to fail our QA testing.
I've done a simple form validation using onBlur() as recommended in all the javascript tutorials I've seen. I am testing only that the text box is not blank, but it still seems to cause an infinite loop in some versions of Netscape 4+. I tried using onChange(), but sometimes this prevents form submission completely IE!
None of these effects happen with any regularity. Three out of 5 textboxes work fine, two cause loops in Netscape. 9 times out of 10 the form submits in IE, but occasionally it will refuse to submit even though the text box is correctly filled out....
I'm just looking for a simple form validation that works in all versions all the time. Can anyone help?
Kat
James Hobson
Ranch Hand

Joined: Aug 28, 2001
Posts: 140
**All the time**??
People will disable javascript (I do) -- so nothing works all the time. Also, have you considered Opera, lynx (yes people do you it, not many, but some), Macs, UNIX, etc.
Bottom line is that javascript is a dog at the best of times, anything you do on the client, you *must* do on the server as well -- so why bother with javascript validation at all?
James
kat luna
Greenhorn

Joined: Jul 20, 2001
Posts: 16
why bother with javascript?
because I'm *just* the web developer (better known here as art school dropout) and the "Developers" insist that all validation be done client-side before the data is returned to the servlet.
I have repeatedly suggested that javascript is a light weight programming language and too dependent on browser versions/settings/etc to be reliable, but the response is "find a way to do it." So I'm here asking for help. The only book I have on Javascript was written for Navigator 2.0 and most of the web tutorials I've looked at are from 1999.
Can anyone recommend anything (books/URL's) that has information on Javascripting for version 4.0 - 6.0 browsers? Please?
Thanks.
Kat
amit patel
Ranch Hand

Joined: Dec 02, 2001
Posts: 32
Q: why bother using javascript?
A:
You tel me what do you do if you don't have server to store you pages? how you gonna use CGI, Cold Fusion well, database ?
There are millions of questions that you will never be able to answer. Javascript remains the only option in this case.
-=A=-

Originally posted by James Hobson:
**All the time**??
People will disable javascript (I do) -- so nothing works all the time. Also, have you considered Opera, lynx (yes people do you it, not many, but some), Macs, UNIX, etc.
Bottom line is that javascript is a dog at the best of times, anything you do on the client, you *must* do on the server as well -- so why bother with javascript validation at all?
James

James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
I have always done form validation in JavaScript in the onSubmit() event handler of the form.
There are annoying differences in the way browsers decide to fire events, and I always get caught with trying to use onBlur/onFocus combination.
Here is some cross-browser JavaScript for simple form validation, it has a nice set of trim methods for checking if a text field is blank (the form is validated via onSubmit() ).

So unless there is a specific need for you to do form validation with onBlur/onFocus combination (or if you don't mind writing different versions of the code for different browsers (nasty), I would avoid it.
James.
kat luna
Greenhorn

Joined: Jul 20, 2001
Posts: 16
Originally posted by james swan:
So unless there is a specific need for you to do form validation with onBlur/onFocus combination (or if you don't mind writing different versions of the code for different browsers (nasty), I would avoid it.
James.[/B]

Hi and thanks for the suggestions. Sadly, our design document says that there MUST be item-by-item validation on each form, not just on form submit.
I have narrowed the problem down to the fact that in Netscape, tabbing out of a textbox places the cursor in the next form object before onBlur() of the previous fires and that is why I am getting an alert loop. (blank textboxB loses focus to display the alert for blank textboxA -- which in turn triggers an alert for blank textboxB which triggers alert for blank textboxA etc...)
In short, I still am at a loss as to how to do item by item validation in Netscape. onChange() avoids the alert loop, but it doesn't fire if the user simply tabs past the textbox without entering any data.
Anyone else have done this successfully?
Thanks in advance,
kat
James Hobson
Ranch Hand

Joined: Aug 28, 2001
Posts: 140
Amit, the question was:
-- so why bother with javascript <em>validation</em> at all?
If you **really** need something to work (if you are an enterprise for example) then javascript is unsafe -- fact.
If you dont have a server, or database etc. then I expect you dont have enterprise needs and so you can rely on javascript.
Javascript has a place, for making rollovers, for highly graphical design over content sites. But for hard core, every mistake costs us a million dollars type work, it simply isnt good enough, use it in addition to server side logic, but dont rely on it.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Hello kat luna, since some people are rather rude here, I will point you to the best online javascript forum on the net. There we are very friendly and helpfull and people know a solution to everything unlike here. The link is http://www.wsabstract.com
Go there and ask your question, and you should have a responce in less then 2 hours
hope this gets you the answer you want.
A1
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Cross browser issues
 
Similar Threads
Shows source code while testing JSP with Netscape 6.10
URL rewriting
What Could Go Wrong?
DOM
required field...but only if enabled