Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未捕获类型错误:无法读取属性';选择开始';空的_Php_Javascript_Html - Fatal编程技术网

Php 未捕获类型错误:无法读取属性';选择开始';空的

Php 未捕获类型错误:无法读取属性';选择开始';空的,php,javascript,html,Php,Javascript,Html,我有一些预先制作的javascript,它与一个表单交互,用于从我的数据库中获取固定的响应。但是,当单击“插入”按钮时,什么也没有发生,chrome显示错误:未捕获类型错误:无法读取null的属性“selectionStart” 以下是javascript/php/html: <tr><?php echo tep_draw_form('status', FILENAME_ORDERS, tep_get_all_get_params(array('action')) . 'ac

我有一些预先制作的javascript,它与一个表单交互,用于从我的数据库中获取固定的响应。但是,当单击“插入”按钮时,什么也没有发生,chrome显示错误:未捕获类型错误:无法读取null的属性“selectionStart”

以下是javascript/php/html:

 <tr><?php echo tep_draw_form('status', FILENAME_ORDERS, tep_get_all_get_params(array('action')) . 'action=update_order'); ?>
         <td class="main">
            <script language="javascript">  
                  function insereTexto(){  
                     //Paste into textarea
                     var textarea = document.getElementById("txt");  

                     //Text to be inserted  
                     var texto = document.getElementById("txtValor").value;  

                     //beginning of the selection 
                     var sel_start = textarea.selectionStart;              

                     //end of the selection  
                     var sel_end = textarea.selectionEnd;  


                     if (!isNaN(textarea.selectionStart))  
                     //Treatment for Mozilla
                     {  
                        var sel_start = textarea.selectionStart;  
                        var sel_end = textarea.selectionEnd;  

                        mozWrap(textarea, texto, '')  
                        textarea.selectionStart = sel_start + texto.length;  
                        textarea.selectionEnd = sel_end + texto.length;  
                     }     

                     else if (textarea.createTextRange && textarea.caretPos)   
                     {  
                        if (baseHeight != textarea.caretPos.boundingHeight)   
                        {  
                           textarea.focus();  
                           storeCaret(textarea);  
                        }        
                        var caret_pos = textarea.caretPos;  
                        caret_pos.text = caret_pos.texto.charAt(caret_pos.texto.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;  

                     }  
                     else //For those who can not enter, insert at the end of it (ie. ..)
                     {  
                        textarea.value = textarea.value + texto;  
                     }        
                  }  

                  /* 
                  This function opens the text of two strings and inserts the text at the cursor position well after he joins novamento text but the text entered
This wonderful feature only works in Mozilla ... IE does not have the properties SelectionStart, textLength ...
                  */  
                  function mozWrap(txtarea, open, close)  
                  {  
                     var selLength = txtarea.textLength;  
                     var selStart = txtarea.selectionStart;  
                     var selEnd = txtarea.selectionEnd;  
                     var scrollTop = txtarea.scrollTop;  

                     if (selEnd == 1 || selEnd == 2)   
                     {  
                        selEnd = selLength;  
                     }  
                     //S1 has the text from the beginning to the cursor position 
                     var s1 = (txtarea.value).substring(0,selStart);  

                     //S2 has the selected text 
                     var s2 = (txtarea.value).substring(selStart, selEnd)  

                     //S3 has all the selected text  
                     var s3 = (txtarea.value).substring(selEnd, selLength);  

                     //Places the text in the textarea. Uses the string that was in the beginning, in the middle of the input string, then the selection string then the
                     //closing and finally what's left after the selection
                     txtarea.value = s1 + open + s2 + close + s3;           
                     txtarea.selectionStart = selEnd + open.length + close.length;  
                     txtarea.selectionEnd = txtarea.selectionStart;  
                     txtarea.focus();  
                     txtarea.scrollTop = scrollTop;  
                     return;  
                  }  
                  /* 
                  Insert at Caret position. Code from 
                   [url]http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130[/url] 
                  */  
                  function storeCaret(textEl)  
                  {  
                        if (textEl.createTextRange)  
                        {  
                           textEl.caretPos = document.selection.createRange().duplicate();  
                        }  
                  }  

                </script>  

                                <select id="txtValor" /> 
                                <option value="">Select Text</option>
                                <option value="<?php echo $order->customer['name']; ?>">Customer Name</option>
                                <option value="<?php echo STORE_NAME_ADDRESS; ?>">signature</option>
                                <option value="<?php echo STORE_NAME; ?>">Store Name</option>
                                <option value="<?php echo $_SERVER['SERVER_NAME']; ?>">Site</option>
                                <option value="<?php echo STORE_OWNER; ?>">Store Owner</option>
                                <option value="<?php echo STORE_OWNER_EMAIL_ADDRESS; ?>">Email the Store</option>
                                <?php
                                $get_premades_query = tep_db_query("select * from orders_premade_comments order by id");
                                while($result = mysql_fetch_array($get_premades_query)) {
                                echo '<option value="'.$result["text"].'">'. $result["title"].'</option>';
                                }
                                ?>
                                </select>
                                <input type="button" value="Insert at the cursor position" onclick="insereTexto()"/>  
                                <input type="button" value="Clean" onclick="this.form.elements['comments'].value=''">
                                    <font class="smallText"><a href="premade_comments.php">[Setup]</a></font><br>


        <?php echo tep_draw_textarea_field('comments', 'soft', '80', '10','','id="txt"'); ?></td>
      </tr>

函数insereTexto(){
//粘贴到文本区域
var textarea=document.getElementById(“txt”);
//要插入的文本
var texto=document.getElementById(“txtValor”).value;
//选择的开始
var sel_start=textarea.selectionStart;
//选择结束
var sel_end=textarea.selectionEnd;
如果(!isNaN(textarea.selectionStart))
//Mozilla的治疗
{  
var sel_start=textarea.selectionStart;
var sel_end=textarea.selectionEnd;
mozWrap(textarea,texto,“”)
textarea.selectionStart=选择开始+texto.length;
textarea.selectionEnd=选择结束+texto.length;
}     
else if(textarea.createTextRange&&textarea.caretPos)
{  
if(baseHeight!=textarea.caretPos.boundingHeight)
{  
textarea.focus();
storeCaret(文本区);
}        
var caret_pos=textarea.caretPos;
插入符号文本=插入符号文本字符(插入符号文本长度-1)=''插入符号文本+文本+'':插入符号文本+文本;
}  
否则//对于无法进入的人,请在其末尾插入(即…)
{  
textarea.value=textarea.value+texto;
}        
}  
/* 
此函数用于打开两个字符串的文本,并在加入Novatemento文本后,在光标位置插入文本,但输入的文本
这个奇妙的功能只在Mozilla中有效。。。IE没有属性SelectionStart、textLength。。。
*/  
函数mozWrap(txtarea,打开,关闭)
{  
var selLength=txtarea.textLength;
var selStart=txtarea.selectionStart;
var selEnd=txtarea.selectionEnd;
var scrollTop=txtarea.scrollTop;
如果(selEnd==1 | | selEnd==2)
{  
selEnd=selLength;
}  
//S1从开始到光标位置都有文本
var s1=(txtarea.value).substring(0,selStart);
//S2包含所选文本
var s2=(txtarea.value).substring(selStart,selEnd)
//S3包含所有选定的文本
var s3=(txtarea.value).substring(selEnd,selLength);
//将文本放置在TetraReA中。使用开始时的字符串,在输入字符串的中间,然后选择字符串
//结束,最后是选择后剩下的内容
txtarea.value=s1+open+s2+close+s3;
txtarea.selectionStart=selEnd+open.length+close.length;
txtarea.selectionEnd=txtarea.selectionStart;
txtarea.focus();
txtarea.scrollTop=scrollTop;
返回;
}  
/* 
插入插入符号位置。代码来自
[网址]http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130[/url]
*/  
函数storeCaret(textEl)
{  
if(textEl.createTextRange)
{  
textEl.caretPos=document.selection.createRange().duplicate();
}  
}  
选择文本

消息说:

Cannot read property 'selectionStart' of null
这是正确的:
null
没有属性,因此它不能有
selectionStart

那么这
null
是从哪里来的呢<代码>。选择启动请求
文本区域

                 //beginning of the selection 
                 var sel_start = textarea.selectionStart;              
textarea
来自DOM:

   //Paste into textarea
   var textarea = document.getElementById("txt");  
显然,
getElementById()
调用返回的是
null
,而不是什么

您应该检查HTML以验证是否存在id为
txt
的文本区域。您还可以添加显式检查,以防这种情况只是间歇性发生:

   //Paste into textarea
   var textarea = document.getElementById("txt");
   if (!textarea)
       alert("Och! No txt textarea defined?");
…发生这种情况时,请检查HTML源代码以验证发生这种情况的原因。可能您并不总是显示文本区域,可能ID发生了变化,等等。

消息说:

Cannot read property 'selectionStart' of null
这是正确的:
null
没有属性,因此它不能有
selectionStart

那么这
null
是从哪里来的呢<代码>。选择启动请求
文本区域

                 //beginning of the selection 
                 var sel_start = textarea.selectionStart;              
textarea
来自DOM:

   //Paste into textarea
   var textarea = document.getElementById("txt");  
显然,
getElementById()
调用返回的是
null
,而不是什么

幽幽