472,958 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Rich Text Form in JavaScript gives error: Object required

Hello,

I found this script to create a simple rich text form
(http://programmabilities.com/xml/index.php?id=17):

<html>
<head>
<title>Rich Text Editor</title>
</head>
<body>
<script language= "JavaScript" type= "text/javascript" src=
"editor.js" >
//First lets initiate some variables

var isEditable= false;
var isIE;
var isGecko;
var isSafari;
var isKonqueror;

function initiateEditor() {
//check what browser is in use
var browser = navigator.userAgent.toLowerCase();
isIE = ((browser .indexOf("msie") != -1) && (browser
..indexOf("opera") == -1) && (browser .indexOf("webtv") == -1));
isGecko = (browser .indexOf("gecko") != -1);
isSafari = (browser .indexOf("safari") != -1);
isKonqueror = (browser.indexOf("konqueror") != -1);

//enable designMode if the browser is not safari or konqueror.
if (document.getElementById && document.designMode && !isSafari &&
!isKonqueror) {
isEditable= true;
}
}
//Javascript function dislpayEditor will create the textarea.

function displayEditor(editor, html, width, height) {
if(isEditable){
document.writeln('<iframe id="' + editor + '" name="' + editor
+ '" width="' + width + 'px" height="' + height + 'px"></iframe>');
//create a hidden field that will hold everything that is typed in the
textarea
document.writeln('<input type="hidden" id="hidden' + editor +
'" name="hidden' + editor + '" value="">');
//assign html (textarea value) to hiddeneditor
document.getElementById('hidden' + editor).value = html;
//call function designer
designer(editor, html);
}else{
document.writeln('<textarea name="' + editor + '" id="' + editor
+ '" cols="39" rows="10">' + html + '</textarea>');
}
}

//this is designer function that enables designMode and writes defalut
text to the text area
function designer(editor, html) {
var mainContent= "<html id=" + editor + "><head></head><body>" +
html + "</body></html>" ;
//assign the frame(textarea) to the edit variable using that frames id
var edit= document.getElementById(editor).contentWindow.docu ment;
//write the content to the textarea
edit.write(mainContent);
//enable the designMode
edit.designMode = "On" ;
document.getElementById(content).contentDocument.d esignMode = "on";
}

//To execute command we will use javascript function editorCommand.
function editorCommand(editor, command, option) {
// first we assign the content of the textarea to the variable
mainField
var mainField;
mainField = document.getElementById(editor).contentWindow;
// then we will use execCommand to execute the option on the textarea
making sure the textarea stays in focus
try {
mainField.focus();
mainField.document.execCommand(command, false, option);
mainField.focus();
} catch (e) { }
}

function updateEditor(editor) {
if (!isEditable) return;
//assign the value of the textarea to the hidden field.
var hiddenField = document.getElementById('hidden' + editor);
if (hiddenField.value == null) hiddenField.value = "";
hiddenField.value =
document.getElementById(editor).contentWindow.docu ment.body.innerHTML;
}
</script>
<table width="750">
<form action="form.asp" name="edit" method="POST" id="edit"
onsubmit="return submitForm();">
<tr>
<td> <a href= "javascript:editorCommand('content', 'bold', '')" ><img
src="bold.gif" width="25" height="24" alt="Bold" title="Bold"
border="0"></a> </td>

<td> <a href= "javascript:editorCommand('content', 'underline', '')"
<img src="underline.gif" width="25" height="24" alt="Underline" title="Underline" border="0"></a> </td>
<td> <a href= "javascript:editorCommand('content', 'italic', '')"<img src="italic.gif" width="25" height="24" alt="Italic" title="Italic" border="0"></a> </td>
<td> <a href= "javascript:editorCommand('content', 'justifyleft', '')"<img src="j_left.gif" width="25" height="24" alt="Align Left" title="Align Left" border="0"></a> </td>
<td> <a href= "javascript:editorCommand('content', 'justifycenter',
'')" ><img src="j_center.gif" width="25" height="24" alt="Align Center"
title="Align Center" border="0"></a> </td>

<td> <a href= "javascript:editorCommand('content', 'justifyright',
'')" ><img src="j_right.gif" width="25" height="24" alt="Align Right"
title="Align Right" border="0"></a> </td>

<td> <a href= "javascript:editorCommand('content', 'indent', '')"<img src="indent.gif" width="25" height="24" alt="Indent" title="Indent" border="0"></a> </td>
<td> <a href= "javascript:editorCommand('content', 'outdent', '')"<img src="outdent.gif" width="25" height="24" alt="Outdent" title="Outdent" border="0"></a> </td>


<td> <a href= "javascript:editorCommand('content', 'undo', '')" ><img
src="undo.gif" width="25" height="24" alt="Undo" title="Undo"
border="0"></a> </td>

<td> <a href= "javascript:editorCommand('content', 'redo', '')" ><img
src="redo.gif" width="25" height="24" alt="Redo" title="Redo"
border="0"></a> </td>

<td width="100%" align="levt">Shift+Enter for single line spacing</td>
</tr>
<tr>
<td colspan="12">
<script language="JavaScript" type="text/javascript">
<!--
function submitForm() {
updateEditor('content');
//alert("content = " + document.edit.hiddencontent.value);
return true;
}

initiateEditor();
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
displayEditor('content', '', 600, 300);
//-->
</script>
</td>
</tr>
<tr><td colspan="12"> <input type="submit" name="Submit"
value="Submit"> </td></tr>
</form>
</table>

</body>
</html>
But it is giving me this error in the status bar of my IE:
Line: 48
Char: 4
Error: Object required
Code: 0
URL: http://bewebmaster.com/editorjs/

Can somebody please help me out on this?

Thanks

Jul 23 '05 #1
1 3688
Hello,

What is actually the use of this line:
document.getElementById(content).contentDocument.d esignMode = 'On';

Because when I mark it out it is still working!

Sorry but I am new in JavaScript.

Thanks

IkBenHet schreef:
Hello,

I found this script to create a simple rich text form
(http://programmabilities.com/xml/index.php?id=17):

<html>
<head>
<title>Rich Text Editor</title>
</head>
<body>
<script language= "JavaScript" type= "text/javascript" src=
"editor.js" >
//First lets initiate some variables

var isEditable= false;
var isIE;
var isGecko;
var isSafari;
var isKonqueror;

function initiateEditor() {
//check what browser is in use
var browser = navigator.userAgent.toLowerCase();
isIE = ((browser .indexOf("msie") != -1) && (browser
.indexOf("opera") == -1) && (browser .indexOf("webtv") == -1));
isGecko = (browser .indexOf("gecko") != -1);
isSafari = (browser .indexOf("safari") != -1);
isKonqueror = (browser.indexOf("konqueror") != -1);

//enable designMode if the browser is not safari or konqueror.
if (document.getElementById && document.designMode && !isSafari &&
!isKonqueror) {
isEditable= true;
}
}
//Javascript function dislpayEditor will create the textarea.

function displayEditor(editor, html, width, height) {
if(isEditable){
document.writeln('<iframe id="' + editor + '" name="' + editor
+ '" width="' + width + 'px" height="' + height + 'px"></iframe>');
//create a hidden field that will hold everything that is typed in the
textarea
document.writeln('<input type="hidden" id="hidden' + editor +
'" name="hidden' + editor + '" value="">');
//assign html (textarea value) to hiddeneditor
document.getElementById('hidden' + editor).value = html;
//call function designer
designer(editor, html);
}else{
document.writeln('<textarea name="' + editor + '" id="' + editor
+ '" cols="39" rows="10">' + html + '</textarea>');
}
}

//this is designer function that enables designMode and writes defalut
text to the text area
function designer(editor, html) {
var mainContent= "<html id=" + editor + "><head></head><body>" +
html + "</body></html>" ;
//assign the frame(textarea) to the edit variable using that frames id
var edit= document.getElementById(editor).contentWindow.docu ment;
//write the content to the textarea
edit.write(mainContent);
//enable the designMode
edit.designMode = "On" ;
document.getElementById(content).contentDocument.d esignMode = "on";
}

//To execute command we will use javascript function editorCommand.
function editorCommand(editor, command, option) {
// first we assign the content of the textarea to the variable
mainField
var mainField;
mainField = document.getElementById(editor).contentWindow;
// then we will use execCommand to execute the option on the textarea
making sure the textarea stays in focus
try {
mainField.focus();
mainField.document.execCommand(command, false, option);
mainField.focus();
} catch (e) { }
}

function updateEditor(editor) {
if (!isEditable) return;
//assign the value of the textarea to the hidden field.
var hiddenField = document.getElementById('hidden' + editor);
if (hiddenField.value == null) hiddenField.value = "";
hiddenField.value =
document.getElementById(editor).contentWindow.docu ment.body.innerHTML;
}
</script>
<table width="750">
<form action="form.asp" name="edit" method="POST" id="edit"
onsubmit="return submitForm();">
<tr>
<td> <a href= "javascript:editorCommand('content', 'bold', '')" ><img
src="bold.gif" width="25" height="24" alt="Bold" title="Bold"
border="0"></a> </td>

<td> <a href= "javascript:editorCommand('content', 'underline', '')"
<img src="underline.gif" width="25" height="24" alt="Underline" title="Underline" border="0"></a> </td>


<td> <a href= "javascript:editorCommand('content', 'italic', '')"
<img src="italic.gif" width="25" height="24" alt="Italic" title="Italic" border="0"></a> </td>


<td> <a href= "javascript:editorCommand('content', 'justifyleft', '')"
<img src="j_left.gif" width="25" height="24" alt="Align Left" title="Align Left" border="0"></a> </td>


<td> <a href= "javascript:editorCommand('content', 'justifycenter',
'')" ><img src="j_center.gif" width="25" height="24" alt="Align Center"
title="Align Center" border="0"></a> </td>

<td> <a href= "javascript:editorCommand('content', 'justifyright',
'')" ><img src="j_right.gif" width="25" height="24" alt="Align Right"
title="Align Right" border="0"></a> </td>

<td> <a href= "javascript:editorCommand('content', 'indent', '')"
<img src="indent.gif" width="25" height="24" alt="Indent" title="Indent" border="0"></a> </td>


<td> <a href= "javascript:editorCommand('content', 'outdent', '')"
<img src="outdent.gif" width="25" height="24" alt="Outdent" title="Outdent" border="0"></a> </td>


<td> <a href= "javascript:editorCommand('content', 'undo', '')" ><img
src="undo.gif" width="25" height="24" alt="Undo" title="Undo"
border="0"></a> </td>

<td> <a href= "javascript:editorCommand('content', 'redo', '')" ><img
src="redo.gif" width="25" height="24" alt="Redo" title="Redo"
border="0"></a> </td>

<td width="100%" align="levt">Shift+Enter for single line spacing</td>
</tr>
<tr>
<td colspan="12">
<script language="JavaScript" type="text/javascript">
<!--
function submitForm() {
updateEditor('content');
//alert("content = " + document.edit.hiddencontent.value);
return true;
}

initiateEditor();
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
displayEditor('content', '', 600, 300);
//-->
</script>
</td>
</tr>
<tr><td colspan="12"> <input type="submit" name="Submit"
value="Submit"> </td></tr>
</form>
</table>

</body>
</html>
But it is giving me this error in the status bar of my IE:
Line: 48
Char: 4
Error: Object required
Code: 0
URL: http://bewebmaster.com/editorjs/

Can somebody please help me out on this?

Thanks


Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chad | last post by:
In our application, I would like to send out HTML mail. TO do so, I must do something like this: Mail.Body = <raw HTMLTEXT String> Hence, I would like to know how to get the HTML text for Web...
5
by: mark_hanson_eng | last post by:
How can I best pass user selected text to the server on a button click? I could use javascript document.selected and add javascript to a asp:button using Attributes.Add. Ideally I would fill the...
11
by: F. Michael Miller | last post by:
I'd like to copy the listing of a directory (& sub directories) to a text file in vb.net. I'm looking for teh equivilant of the DOS command dir /s > TargetFile.txt. Thanks!
9
by: B-Dog | last post by:
I have a form that has about 10 text boxes on it, they all have to be filled out before submitting is there a quick way to make sure that none are null or do I have to call out each textbox? Say...
4
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person...
9
by: Jason | last post by:
If I've got Me.RichTextBox1.Text = "In Ricn Tex Box" Me.RichTextBox1.Text &= "Line two" & vbCrLf How do I make the first line appear BOLD?
36
by: karen987 | last post by:
My newsweblog has ASP pages with news articles and a commenting system. The comments are posted, and to read them the reader clicks on the headline of the comment, and it opens up in a pop up window....
11
by: karen987 | last post by:
I have a web page which used to work fine until i added a rich text editor. the pages are in ASP and it is a news weblog, with a comments section where people click the headline of a comment and...
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.