Error: 'document.response.createTextRange' is null or not an object

Posted on 2003-03-05
Medium Priority
Last Modified: 2008-02-01
Hi All,

Ive been racking my brains for hours and tried SOOO many sites, im having a problem with a relatively old helpdesk script, the developer ditched it a year ago, and we still use it due to the amount of info it contains.

Anyway, the javascript code is as follows

<script language='JavaScript'>
function getActiveText(selectedtext) {
        text = (document.all) ? document.selection.createRange().text : document.getSelection();
        if (selectedtext.createTextRange) {
        selectedtext.caretPos = document.selection.createRange().duplicate();
        return true;
function quick(Quick) {
if (Quick != 0) {
        if (document.reply.response.createTextRange && document.reply.response.caretPos) {
                var caretPos = document.reply.response.caretPos;
                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? Quick + ' ' : Quick;
        } else {
        document.reply.quickselect.selectedIndex = 0;

Later on, we have a ListBox with the following

<textarea name='response' rows=10 cols=77 wrap=VIRTUAL  onChange=getActiveText(this) onclick=getActiveText(this)  

                <select onChange='quick(this.options[this.selectedIndex].value)' name='quickselect'>

                <option value='0'>Quick Response</option>
                <option value='Testing Quick Response'>Test</option>


I dont know whats wrong :(
Anyone help me out a little?
Question by:kevc978
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 46

Expert Comment

ID: 8075843
What is the problem exactly?

Fritz the Blank

Author Comment

ID: 8075873
whats suppose to happen is, the Helpdesk operator selects the correct "Quick Response" option from the listbox, and it gets automatically put into the Text Area instead of the Operator typing it.

The problem is, when we select ANY of the options, none of them appear.

we get an error of :
Line: 81
char: 9
Error: 'document.reply.response.createTextRange' is null or not an object

Accepted Solution

cirtap earned 300 total points
ID: 8076479
Hi kev,

I assume line 81 is the one that says:
if (document.reply.response.createTextRange && document.reply.response.caretPos) {

It would help alot if you'd tell us WHAT browser you're using. NS6+ knows the TextRange object but handles them differnt from MSIE.

says: use the <FORM> in the current document (~ <body>) having the ID or NAME "reply"
within this form execute the createTextRange() method on an element having the ID or NAME "response".

The page has either more than one FORM called "reply", which makes it document.reply[] -- an *array* -- OR the textarea in not (no more) in that particular FORM, OR responce was changed into an INPUT element OR there's more than one "response" element in the FORM, eg. a checkbox, a button etc.

Then: only the TEXTAREA control has a createTextRange method, INPUT controls do not.

This code is for MSIE4-6 and up only, as Netscape (even 6) does not know the .caretPos property.

Using this handy "bells'n'jingles" property allows the script to "inject" new text at a certain position wheras the else-part will simply append it to the textarea's value:
but still requires a valid form/textarea hierarchy.

 <form name="reply" id="reply">
  <textarea name="response" id="reponse"></textarea>

Double check the HTML code of the page, in case someone fooled around with it and make sure it's as "valid as possible".
CLOSE all tags if neccessary, that might be left open.
As you said it's an "old" page, the HTML may be "invalid" and maybe a litte bit sloppy (although it still may "look" okay.

Check if there's a DOCTYPE that claims the file to be XHTML1 or HTML4 - remove it, to let the browser (MSIE 6?) be less restrictive.

Hope this helps

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more


Expert Comment

ID: 8076499
err: createTextRange() applies to INPUT as well.
BODY, BUTTON, INPUT type=button, INPUT type=hidden, INPUT type=password, INPUT type=reset, INPUT type=submit, INPUT type=text, TEXTAREA


Author Comment

ID: 8076538

Your a Genius.

Last week our HTML "Guru" added an extra form for staff notes, we suspected it might have been this and had him "tinker" with it, but after removing it, all seems well!!!

Thanks for the answer!


Author Comment

ID: 8076541
Well Done!!!

Expert Comment

ID: 8077148
glad to help :-)

well know cut-n-paste issues

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question