Hello all,
I would like to insert text into an fckeditor textfield by javascript. Unfortunately this does not work. Could you explain me how I can get this to work?
I use a normal textarea with FCKEditor and it works if i replace the fckeditor with an normal textarea?!
Thanks in advance!
Uwe
Here is the full example:
<!--
function insert(textToInsert) {
var input = document.newsform.news_text;
input.focus();
if(typeof document.selection != 'undefined') {
var range = document.selection.createRange();
var insText = range.text;
range.text = textToInsert;
range = document.selection.createRange();
range.moveStart('character', insText.length);
range.select();
}
else if(typeof input.selectionStart != 'undefined')
{
var start = input.selectionStart;
var end = input.selectionEnd;
input.value = input.value.substr(0, start) + textToInsert + input.value.substr(end);
var pos;
pos = start + textToInsert.length;
input.selectionStart = pos;
input.selectionEnd = pos;
}
else
{
alert("You are not using Internet Explorer or Gecko based Browser. Please note, that the text is pasted at the end.");
/* get insert cursor position */
pos = input.value.length;
/* insert text */
input.value = input.value.substr(0, pos) + textToInsert + input.value.substr(pos);
}
}
function insertID(id)
{
if (isNaN(id)||(id.length==0)||(id.length>7)){
alert("Incorrect ID!");
} else {
insert(" #TID#" + "0000000".substr(0, 7-id.length) + id + "#TID# ");
document.newsform.news_text.focus();
}
}
//-->
</script>
<form name="newsform" method="POST" action="index.php?adminaction=adminnews&global_ready=yes&nid=&ready=true&edit=">
<table class="itable">
<tr>
<td>
<span class="shline">Administration News</span>
</td>
</tr>
<tr>
<td colspan="2">
<span class="sftext">
Please edit the news. If you want to insert an external news ID, use the button.
</span>
<input type="text" name="ID">
<input type="button" class="sbutton" value="Insert ID" onClick="insertID(this.form.ID.value)">
</td>
</tr>
<tr>
<td>
<div><input type="hidden" id="news_text" name="news_text" value="" /><input type="hidden" id="news_text___Config" value="" /><iframe id="news_text___Frame" src="/external_fckeditor/editor/fckeditor.html?InstanceName=news_text&Toolbar=Default" width="500" height="300" frameborder="no" scrolling="no"></iframe></div> </td>
</tr>
<tr>
<td align="center">
<input class="sbutton" type="submit" value="Done">
</td>
</tr>
</table>
</form>
I would like to insert text into an fckeditor textfield by javascript. Unfortunately this does not work. Could you explain me how I can get this to work?
I use a normal textarea with FCKEditor and it works if i replace the fckeditor with an normal textarea?!
Thanks in advance!
Uwe
Here is the full example:
<!--
function insert(textToInsert) {
var input = document.newsform.news_text;
input.focus();
if(typeof document.selection != 'undefined') {
var range = document.selection.createRange();
var insText = range.text;
range.text = textToInsert;
range = document.selection.createRange();
range.moveStart('character', insText.length);
range.select();
}
else if(typeof input.selectionStart != 'undefined')
{
var start = input.selectionStart;
var end = input.selectionEnd;
input.value = input.value.substr(0, start) + textToInsert + input.value.substr(end);
var pos;
pos = start + textToInsert.length;
input.selectionStart = pos;
input.selectionEnd = pos;
}
else
{
alert("You are not using Internet Explorer or Gecko based Browser. Please note, that the text is pasted at the end.");
/* get insert cursor position */
pos = input.value.length;
/* insert text */
input.value = input.value.substr(0, pos) + textToInsert + input.value.substr(pos);
}
}
function insertID(id)
{
if (isNaN(id)||(id.length==0)||(id.length>7)){
alert("Incorrect ID!");
} else {
insert(" #TID#" + "0000000".substr(0, 7-id.length) + id + "#TID# ");
document.newsform.news_text.focus();
}
}
//-->
</script>
<form name="newsform" method="POST" action="index.php?adminaction=adminnews&global_ready=yes&nid=&ready=true&edit=">
<table class="itable">
<tr>
<td>
<span class="shline">Administration News</span>
</td>
</tr>
<tr>
<td colspan="2">
<span class="sftext">
Please edit the news. If you want to insert an external news ID, use the button.
</span>
<input type="text" name="ID">
<input type="button" class="sbutton" value="Insert ID" onClick="insertID(this.form.ID.value)">
</td>
</tr>
<tr>
<td>
<div><input type="hidden" id="news_text" name="news_text" value="" /><input type="hidden" id="news_text___Config" value="" /><iframe id="news_text___Frame" src="/external_fckeditor/editor/fckeditor.html?InstanceName=news_text&Toolbar=Default" width="500" height="300" frameborder="no" scrolling="no"></iframe></div> </td>
</tr>
<tr>
<td align="center">
<input class="sbutton" type="submit" value="Done">
</td>
</tr>
</table>
</form>
RE: Insert to fckeditor with javascript
RE: Insert to fckeditor with javascript
RE: Insert to fckeditor with javascript
under _samples/html ?