Newbie Javascript questions

Javascript coding ..

Moderators: macek, egami, gesf

ktsirig
New php-forum User
New php-forum User
Posts: 36
Joined: Mon Sep 19, 2005 12:22 pm

Newbie Javascript questions

Postby ktsirig » Sat Mar 11, 2006 2:59 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?

User avatar
Coditor
New php-forum User
New php-forum User
Posts: 243
Joined: Wed Feb 01, 2006 9:18 am
Location: Netherlands
Contact:

Postby Coditor » Mon Mar 13, 2006 11:04 am

1) You don't. Normally I use JS for form validation too, and also do some validation in the form's action (PHP script). If JS is disabled, at least you can check in PHP. Not many people have JS disable by the way.

2) That can be achieved by this:

Code: Select all

<a href="http://www.php-forum.com/" target="_blank" onclick="window.open(this.href,'forum','width=800,height=600');return false;">click here</a>

The 'return false' means that the click doesn't trigger the regular respons from an <a href> tag (ie open the page). If JS is disabled, the onclick event cannot be executed, so the 'return false' is not executed and the regular response will be triggered.

Coditor


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest

cron