Click to See Complete Forum and Search --> : Newbie Javascript questions


ktsirig
03-11-2006, 07:02 AM
Hello all!
I am starting to use JS a couple of days now and mainly I am interested in using it in form validation and to create pop-ups.
I have 2 questions :

1) If a user doesn't have JS enabled, how will I check for empty fields in the form and show an alert box that prompts for corrections?

2) Also, I have seen sites that have the following : There is a link somewhere which works like this : [a] if you have JS enabled, it "recognizes" it and gives a pop-up window when clicked whereas [b] if you don't have JS enabled, it simply acts like a link and opens a new window (not a poup-up one).

Because I am a bit confused, I am starting to think that maybe JS causes more problems than it solves... Should a programmer use it or ,for instance, do a form validation in another page and don't count on the user having JS enabled?

Skull
03-11-2006, 07:09 AM
1) You have the server side script check for errors aswell as the clientside javascript check. That way if they don't have Javascript turned on, your server side script can do the validation.

2) <a href="new.html" target="_new" class="popup">Text</a>

when the page loads, you call a javascript function which loops through all of the anchor tags that have the classname popup and change the href to a javascript function which opens a pop up. If the user doesn't have javascript turned on, then it won't change thte anchor tags leaving just a normal hyperlink which opens in a new window.

You should think of javascript as more of an extra rather than an alternative. For the people who have it turned on, they get things working faster (such as client-side validation) and for those who have it off, they just have things work the normal way.