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.response.value+=Quick
        }
        document.reply.response.focus();
        document.reply.quickselect.selectedIndex = 0;
}
}
</script>



Later on, we have a ListBox with the following




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

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

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

                </select></td>


I dont know whats wrong :(
Anyone help me out a little?
kevc978Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fritz_the_blankCommented:
What is the problem exactly?

Fritz the Blank
0
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
0
cirtapCommented:
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.

document.reply.response.createTextRange
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:
  document.reply.response.value+=Quick
but still requires a valid form/textarea hierarchy.

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

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

CirTap
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

cirtapCommented:
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

0
kevc978Author Commented:
yay!

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!

Kevin
0
kevc978Author Commented:
Well Done!!!
0
cirtapCommented:
glad to help :-)

well know cut-n-paste issues
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.