Forum Moderators: open
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?
Regarding your second question, you could do something like:
links = document.getElementsByTagName("a");
for (i=0; i<links.length; i++) {
links[i].target = "_blank";
} In English: get all the links in the document, and give them a target of _blank to force them to open in a new window. Of course that's very simplisitic and desn't deal with anchors / new window sizing / etc, but you get the idea.
[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).
I think what is wanted is something slightly different, Robin. By "popup", ktsirig means a simple popup with defined dimensions and features. When JS is disabled, a new window is still required.
So it's easier to include the target="_blank" in the HTML as the fallback, rather than the main feature.
<a href="mypage.htm" target="_blank" onclick="popup(this.href);return false;"> That is pretty much the standard pattern.
(popup is a custom function where you keep all the fiddly details of the desired window features )