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 2 of 2
  1. #1
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts

    Use execCommand in textarea.

    Hey, I'd like to build a spell checker and I found the command execCommand that should help me do that but at all the websites I looked up, I never found what my problem is.
    This is my code:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var spellchecker = function(sName, Height, Width)
    {
    	this.name = sName;
    	this.Height = Height || "100px";
    	this.Width = Width || "100%";
    }
    spellchecker.prototype.Create = function()
    {
    	if(!this.name)
    	{
    		alert("Error code 0: Illegal parameter value (name).");
    		window.status = 'Illegal parameter value (name)';
    		return false;
    	}
    	this.toolbox();
    	document.write("<textarea id=\"" + this.name + "\" style=\"height: " + this.Height + "; width: " + this.Width + "\" name=\"" + this.name + "\"></textarea>");
    	/*element = document.getElementsByName(this.name);
    	if(element.insertAdjacentHTML)
    		element.insertAdjacentHTML('beforeBegin','<iframe frameborder="0" src="toolbox.html" height="' + this.Height + '" width="' + this.Width + '"></iframe>');*/
    };
    spellchecker.prototype.toolbox = function()
    {
    	sHtml = '<table><tr><td><a id="bold" href="#">bold</a></td></tr></table>';
    	document.write(sHtml);
    	var oThis = this;
    	document.getElementById("bold").onclick = function()
    	{
    		var obj = document.getElementById(oThis.name);
    		/*var oRange = obj.createTextRange();
    		oRange.moveStart("character",*/
    		try
    		{
    		obj.focus();
    		var oRange = obj.createTextRange();
    		oRange.moveStart("character",0);
    		oRange.moveEnd("character",obj.length);
    		oRange.execCommand("bold");
    		obj.focus();
    		}
    		catch(e){alert("Error " + e.number + ": " + e.description);}
    		return false;
    	};
    };
    </script>
    </head>
    <body>
    <script type="text/javascript">
    var oSpellchecker = new spellchecker("test");
    oSpellchecker.Height = "200px";
    oSpellchecker.Width = "300px";
    oSpellchecker.Create();
    </script>
    </body>
    </html>
    In here I tried using bold just to try and check the command but it doesn't work.

    Any suggestions?
    Thanks.

  • #2
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    bump.


  •  

    Posting Permissions

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