我有一个函数,用于侦听onkeyup事件,onkeyup检查是否有一个框有一个值,如果不是空白,应该拉一个elementID的值,这是从另一个调用的电话号码页。它接受该值并将其插入到发送给另一个elementID的html代码片段中。下面的代码是功能和相关的代码。加载,但使用Smarty模板是写在单独的页面时document.getElementById是NULL错误
<script language="javascript">
function monthlycheck() {
var mnthchk = document.getElementById("mdamountBox");
var cancelPhone = document.getElementById("cancelphoneLabel");
document.getElementById("cancelphonelistLabel").value = cancelPhone; <--gives the is null error
if(mnthchk.value!=""){
var newHTML = "<span style='color:#24D330'> Your Monthly pledge in the amount of $__ is valid and will be deducted this time every month<br> untill you notify us of its cancellation by calling <label id='cancelphonelistLabel'> </label>";
" </span>";
document.getElementById("mnthlychkdiscoLabel").innerHTML = newHTML;
}
}
</script>
<label id="mnthlychkdiscoLabel"> </label> <---this is where the final data is to be displayed
<label id="cancelphoneLabel">1-800-555-1111</label> <--- this is the phone number pulled from another page,
所有的数据都在一个页面拉到一起。我不断收到有关错误,并尝试了许多不同的事情来解决它,但即时通讯任何帮助非常感谢。
这里是一个jfiddle http://jsfiddle.net/rn5HH/
另一页?你可以访问另一个页面的元素? – 2013-05-13 21:43:14
你可以扔在小提琴吗? – samayo 2013-05-13 21:44:30