Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

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

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?
  • 3
  • 3
1 Solution
What is the problem exactly?

Fritz the Blank
kevc978Author Commented:
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
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

kevc978Author Commented:

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!

kevc978Author Commented:
Well Done!!!
glad to help :-)

well know cut-n-paste issues

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now