uncaught typeerror无法读取null的属性'value'

时间:2014-01-24 12:17:51

标签: javascript html

我绝对没有Javascript知识。我纯粹是一个SQL / Report人,但我设法拼凑了一些代码,以便每次选择一个下拉框时都会更新“消息框”。

e.g。

Dropdown有“Joe Bloggs”和“Mrs Bloggs”。

文字框说

Dropdown选择了“Joe Bloggs”

“我的名字是Joe Bloggs”

如果我从DropDown中选择“Mrs Bloggs”,则文本框会在那里更改,然后更改为“我的名字是Mrs Bloggs”

这对我来说是早期版本的IE / Chrome,但由于某种原因,更新后不再有用。

我在所有下拉列表的onChange属性中都有这个函数。

<script type="text/javascript">
function changeMessageText()
{

var messagetxt = document.getElementById('message').value;

var QValue = document.getElementById('QValue').value;
var Cover = document.getElementById('Cover').value;
var Excess = document.getElementById('Excess').value;
var Indem = document.getElementById('Indemnity').value;
var Advisor = document.getElementById('Advisor').value;

var messagetxt=messagetxt.replace("[QValue]", QValue);
var messagetxt=messagetxt.replace("[Cover]", Cover);
var messagetxt=messagetxt.replace("[Excess]", Excess);
var messagetxt=messagetxt.replace("[Indem]", Indem);

var messagetxt2 = messagetxt.substr(0,14);

var cover = messagetxt.search("TPO");

//Sets the original message text
if (messagetxt2=="We are pleased") 
{document.getElementById('messageText').innerHTML = messagetxt+" Please Call "+Advisor}
else if (messagetxt2=="I have managed") 
{document.getElementById('messageText').innerHTML = messagetxt+" Please Call "+Advisor+ " Thanks Fresh MT"}
else 
{document.getElementById('messageText').innerHTML = messagetxt}; 

//If the CoverType is TPO then it replaces the text with this
if (cover>0) {messagetxt=messagetxt.replace('the Excess is GBP '+Excess+' and Indemnity '+Indem ,"there is No Excess and No Indemnity.")}

//Sets the message text again if it has changed
if (messagetxt2=="We are pleased") 
{document.getElementById('messageText').innerHTML = messagetxt+" Please Call "+Advisor}
else if (messagetxt2=="I have managed") 
{document.getElementById('messageText').innerHTML = messagetxt+" Please Call "+Advisor+ " Thanks Fresh MT"}
else 
{document.getElementById('messageText').innerHTML = messagetxt}; 

}

</script>

有人可以为我解释这个问题吗?

更新:

获得

Uncaught TypeError: Cannot read property 'value' of null TextITMotorTrade-Backup.asp:12
changeMessageText TextITMotorTrade-Backup.asp:12
onchange

现在

changeMes​​sageText是我在表单的onChange上调用的函数的名称。

在@Niklas回复后,我现在收到以下错误:

Uncaught TypeError: Cannot read property 'value' of null TextITMotorTrade-Backup.asp:187
(anonymous function) TextITMotorTrade-Backup.asp:187
Uncaught TypeError: Cannot set property 'innerHTML' of null TextITMotorTrade-Backup.asp:35
changeMessageText TextITMotorTrade-Backup.asp:35
onchange

我已经仔细检查了正确的拼写,并且字符的大小写是一致的。

额外信息 - 这适用于IE8,但不适用于Chrome,Firefox或IE11 ** 那么在更新浏览器时代码中是否存在某些变化?

的Ta。

0 个答案:

没有答案