Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checking for Javascript

    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.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking for Javascript

    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?!

  • #4
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What is the <noscript> tag and how can I use it?

  • #6
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation A little clarification

    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>:
    Code:
    <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)
    Last edited by brothercake; 04-08-2003 at 01:33 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #8
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for all the suggestions.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •