0x800a138f - JavaScript运行时错误:无法获取未定义或空引用的属性“值” [英] 0x800a138f - JavaScript runtime error: Unable to get property 'value' of undefined or null reference
问题描述
我已经写了一个javascript代码来比较来自2个文本框的2dates
$ b $ pre $函数CompareDates(){
var fdate = document.getElementById('txtFromDate');
var edate = document.getElementById('txtToDate');
var FromDate = fdate.value.split('/');
var EndDate = edate.value.split('/');
var val ='false';如果(parseInt(FromDate [2])< parseInt(EndDate [2])){
val ='true';
if
返回true; $ pa
$ b else if(parseInt(FromDate [2])== parseInt(EndDate [2])){
if(parseInt(FromDate [0])< parseInt(EndDate [0 ])){
val ='true';
返回true; $ pa
$ b else if(parseInt(FromDate [0])== parseInt(EndDate [0])){
if(parseInt(FromDate [1])< = parseInt(EndDate [ 1])){
val ='true';
返回true;
$ b if(val ==false){
alert(FromDate Always Less To ToDate);
返回false;
$ / code $ / pre
$ b $ 和html代码
< asp:TextBox ID =txtFromDaterunat =serverWidth =150px/>
ID =ceFromDate
TargetControlID =txtFromDate
Format =dd / MM / yyyy />
< asp:TextBox ID =txtToDaterunat =serverwidth =150px/>
< ajaxToolkit:CalendarExtender CssClass =MyCalendarrunat =server
ID =ceToDAte
TargetControlID =txtToDate
Format =dd / MM / yyyy />
< asp:Button ID =btnGeneraterunat =serverCssClass =button
Text =GenerateOnClientClick =if(!CompareDates())return false;
OnClick =btnGenerate_Click/>
问题在于页面在Chrome中运行良好,但是当我在IE中运行我的应用程序时,它抛出错误
0x800a138f - JavaScript运行时错误:无法获取未定义或空引用的属性'值'
请帮我解决这个问题。
错误在这里:
var fdate = document.getElementById('txtFromDate');
var edate = document.getElementById('txtToDate');
问题在于 txtFromDate
和 txtToDate
是控件的服务器名称,而不是客户端名称(查看浏览器页面的源代码)。
试试这:
var fdate = document.getElementById('<%= txtFromDate.ClientID%>');
var edate = document.getElementById('<%= txtToDate.ClientID%>');
i have written a javascript code to compare 2dates from 2 textboxes
function CompareDates() {
var fdate = document.getElementById('txtFromDate');
var edate = document.getElementById('txtToDate');
var FromDate = fdate.value.split('/');
var EndDate = edate.value.split('/');
var val = 'false';
if (parseInt(FromDate[2]) < parseInt(EndDate[2])) {
val = 'true';
return true;
}
else if (parseInt(FromDate[2]) == parseInt(EndDate[2])) {
if (parseInt(FromDate[0]) < parseInt(EndDate[0])) {
val = 'true';
return true;
}
else if (parseInt(FromDate[0]) == parseInt(EndDate[0])) {
if (parseInt(FromDate[1]) <= parseInt(EndDate[1])) {
val = 'true';
return true;
}
}
}
if (val == "false") {
alert("FromDate Always Less Than ToDate");
return false;
}
}
and html code is
<asp:TextBox ID="txtFromDate" runat="server" Width="150px" />
<ajaxToolkit:CalendarExtender CssClass="MyCalendar" runat="server"
ID="ceFromDate"
TargetControlID="txtFromDate"
Format="dd/MM/yyyy" />
<asp:TextBox ID="txtToDate" runat="server" Width="150px" />
<ajaxToolkit:CalendarExtender CssClass="MyCalendar" runat="server"
ID="ceToDAte"
TargetControlID="txtToDate"
Format="dd/MM/yyyy" />
<asp:Button ID="btnGenerate" runat="server" CssClass="button"
Text="Generate" OnClientClick="if(!CompareDates()) return false;"
OnClick="btnGenerate_Click" />
the problem is that the page is running well in chrome but when i run my application in IE it throw an error
0x800a138f - JavaScript runtime error: Unable to get property 'value' of undefined or null reference
please help me to overcome from this problem.
The error is here:
var fdate = document.getElementById('txtFromDate');
var edate = document.getElementById('txtToDate');
The problem is that txtFromDate
and txtToDate
are the server name of controls, not the client name (look the source of page from the browser).
Try this:
var fdate = document.getElementById('<%=txtFromDate.ClientID%>');
var edate = document.getElementById('<%=txtToDate.ClientID%>');
这篇关于0x800a138f - JavaScript运行时错误:无法获取未定义或空引用的属性“值”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!