...

View Full Version : Checking for Javascript



florida
04-07-2003, 06:01 PM
I have a form that uses JavaScript for form validations. Anyway I can put something in the Javascript to check if Javascript has been disabled on the user's browser? We have Netscape 4 and IE 5.5 browsers.

I was hoping if the JavaScript was disabled, to send alert message and return false.

liorean
04-07-2003, 06:11 PM
You can't alert OR return false unless javascript is on. You'll have to use serverside validation as a backup for when the javascript validation doesn't work.

ConfusedOfLife
04-07-2003, 08:30 PM
Originally posted by florida
I have a form that uses JavaScript for form validations. Anyway I can put something in the Javascript to check if Javascript has been disabled on the user's browser? We have Netscape 4 and IE 5.5 browsers.

I was hoping if the JavaScript was disabled, to send alert message and return false.

If it's disabled, how would it get excecuted?!

gr66nman
04-07-2003, 09:38 PM
you could use the <noscript> tag to ouput html for the javascript-disabled folk. and use javascript's document.write to output stuff only for those with javascript. Form validation in particular is often best handled using server-side script.

florida
04-08-2003, 12:36 PM
What is the <noscript> tag and how can I use it?

gr66nman
04-08-2003, 12:41 PM
Example:

<script language="javascript" type="text/javascript">
document.write('<' + 'input type="submit" value="Submit"' + '>')
</script>
<noscript>
Hey man, you don't have javascript enabled! You heathen!
<a href="http://www.google.com">I like google</a>
</noscript>

What this example does is display an input button to submit a form if they have javascript or scorn the user if they have javascript disabled. :)

Hope this helps!

Jonathan

brothercake
04-08-2003, 01:26 PM
The purpose of <noscript> is to provide alternative content for browsers who don't or can't support javascript. It should not be used for telling people to enable javascript - you don't know that they can control it.

Here is an example of how to use <noscript>:


<script type="text/javascript">

// some javascript that makes a news ticker

</script>
<noscript>
<ul>
<li>The same news ticker articles</li>
<li>In the form of</li>
<li>Static HTML</li>
</ul>
</noscript>

In rare and extreme circumstances, the <noscript> element may be used to inform visitors that x bit of functionality relies on javascript, and so won't work in their browser. But you should only do this if a static equivalent is impossible or ridiculously impractical.

In the case of form validation - <noscript> content cannot perform the same function; you really need to validate it on the server as well, in which case no <noscript> content is necessary (providing the form is static HTML, that is)

florida
04-08-2003, 02:41 PM
Thanks for all the suggestions.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum