...

View Full Version : Use execCommand in textarea.



BarrMan
02-20-2007, 12:52 PM
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:

<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.

BarrMan
02-22-2007, 12:08 PM
bump.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum