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 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Spell Check Button

    Hey, everyone! I was wondering if there was anyway to make a spell check button with JavaScript?

    I had an idea to disable spell check and then add a button so the user could click it to use spell check...or at least reveal the misspelled words. I'm sure that it's possible. In fact, I have a general idea of how it might be accomplished, but I'm not a JS coder so I don't know exactly how to make it work. Could anyone help, please?

    - Lono

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Google for Javascript Spell Checkers. I don't understand what you mean by "disable spell check".

    All these Eastern Europeans who are flocking in - where are they coming from? - Channel Five

  • #3
    New Coder
    Join Date
    Jul 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    When I say disable spell check, I mean using the CSS attribute to turn off spell check in a browser (spellcheck="false").

    I know about the JS Spell Checker. That's not what I was talking about. Basically, I would have this:

    Code:
    <textarea name="Comments" spellcheck="false"></textarea>
    <input type="button" value="Spell Check" onClick="onClickCheck(this)">
    That disables the default spell checker in the browser for the text area box. Then I would have something like this (Please, excuse the crudeness and ignorance of this. I am not a JS coder. This will just get my idea across.):

    Code:
    function onClickCheck() {
    	var sc = textarea.spellcheck
    	if(sc = "false") {
    		textarea.spellcheck="true"
    	}
    }
    I know that is not even close to accurate JS coding, but it should give an idea of what I'm trying to do. Essentially, the button would re-enable the browser's spell check feature that was disabled by the CSS attribute. I know that seems a bit pointless, but it's something we thought might be a neat feature. Thanks!

    - Lono
    Last edited by lonogod; 08-01-2010 at 07:17 PM.

  • #4
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    353
    Thanks
    9
    Thanked 52 Times in 51 Posts
    Helo lonogod,

    Spellcheck attribute is part of the new HTML5 spec,
    and only few modern browsers support this feature.

    My FF could simulate the feature,
    but only if I've enabled "Check my spelling as I type" option:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    >
    <
    html xmlns="http://www.w3.org/1999/xhtml">

    <
    head>
    <
    meta content="text/html; charset=utf-8" http-equiv="content-type" />

    <
    script type="text/javascript">
    //<![CDATA[
      
    function is_checked(el){
        
    document.getElementById("ta").spellcheck el.checked;
      }
    //]]>
    </script>

    </head>

    <body>
      <textarea id="ta" spellcheck="false"></textarea>
      <br /><span>spellcheck</span>
      <input type="checkbox" onclick="is_checked(this)" />
    </body>

    </html> 
    Hendra

  • Users who have thanked hdewantara for this post:

    lonogod (08-03-2010)

  • #5
    New Coder
    Join Date
    Jul 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I got what I need.

    This is what I was trying to do.
    Code:
    <html>
    <head>
    
    <script language="JavaScript">
    function onClickCheck() {
    	var sc = document.getElementsByName('Comments')[0];
    	if(!sc.spellcheck) {
    		sc.spellcheck = "true";
    	}
    }
    </script>
    
    </head>
    <body>
    
    <form method="post">
    <textarea name="Comments" spellcheck="false"></textarea><br>
    <input type="button" value="Spell Check" onClick="onClickCheck()">
    </form>
    
    </body>
    </html>
    Obviously it only works when the user has that feature enabled on their browser and only if the browser has a built in spell check function. Feel free to use this if you need it anyone! Thanks for everything!

    - Lono


  •  

    Posting Permissions

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