Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an execCommand change the font type for my wysiwyg?

I can make the font bold using a button but not when choosing fonts using the select tag. I have a series of choices such as Arial, Times, Courier etc. with no way of clicking. This is what the code looks like

function fontEditor(){
var x=document.getElementById("fontName").selectedIndex;
var y=document.getElementById("fontName").options;
document.execCommand(x,"",y);
edit.document.focus(fontName);
}

Along with this

<select id="fontName" onChange="fontEditor('font',[selectedIndex].value)">
<option value="Arial">Arial</option>
<option value="Calibri">Calibri</option>
<option value="Comic Sans MS">Comic Sans MS</option>
</select>
like image 773
user1927513 Avatar asked Jan 07 '13 05:01

user1927513


1 Answers

Try changing function fontEditor() to function fontEditor(fontName).

function fontEditor(fontName) {
    document.execCommand("fontName", false, fontName);
    ...
}

And:

<select onchange="fontEditor(this[this.selectedIndex].value)">
    <option value="Arial">Arial</option>
    <option value="Calibri">Calibri</option>
    <option value="Comic Sans MS">Comic Sans MS</option>
</select>
like image 166
K-Gun Avatar answered Oct 06 '22 01:10

K-Gun