运行以下代码时出错。善意的帮助 [英] Error coming while running the following code. kindly help

查看:94
本文介绍了运行以下代码时出错。善意的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码显示错误JavaScript运行时错误:无法获取未定义或空引用的属性值



The following code showing the error JavaScript runtime error: Unable to get property 'value' of undefined or null reference

for (var i = 1; i <= document.getElementById("<%= txtQuantity.ClientID%>").value; i++) {
           for (var j = i - 1; j <= document.getElementById("<%= txtQuantity.ClientID%>").value; j++) {

               var id = "txt" + i;
               var nd = "txt" + j;

               var txtbox1 = document.getElementById(id);
               var txtbox2 = document.getElementById(nd);
               if ((txtbox1.value == txtbox2.value) && (i != j)) {

                   alert("Enter Unique values");

                   return false;
               }
           }
       }

推荐答案

你得到的错误意味着getElementById找不到您找到的元素...

您正在寻找id 'txt'+ [某个数字] 的元素,范围从0到txtQuantity的值...

你有所有这些元素吗?当然不是......使用浏览器内置的调试器来查找缺少的id ...
The error you got means that getElementById was unable to found the element you looked for...
You are looking for elements with id 'txt' + [some number], ranged from 0 to the value of txtQuantity...
Do you have all those elements in place? Of course not...Use browser built in debugger to find out on what id is missing...


这篇关于运行以下代码时出错。善意的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆