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


ktsirig
March 11th, 2006, 04:06 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 staring 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?

hspc
March 11th, 2006, 04:18 AM
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?

Make validations on the server side after the user posts the form..display the errors in the HTML using a differenct color..

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).

You can check if the user enabled javascript or not..and output the code according to this..
check this article:
http://www.faqts.com/knowledge_base/view.phtml/aid/323

Because I am a bit confused, I am staring 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?
Make the user that enables javascript benifit from it,,but you should always make your web site work without it..
If you make a web based application for a customer not a public website,,you can require the users to enable javascript.

degsy
March 15th, 2006, 09:04 AM
For popups you can create the normal link then have the javascript to do it's own code and disable the link by using return false.


<a href="http://www.google.com" target="_blank" onclick="window.open(this.href,'_blank','height=300, width=300'); return false">Google.com</a>