JS Error, need a fresh pair of eyes to look at it

L

Luminousc

I get the dreaded, 'is null or not an object' at runtime. This happens
on the:
" if (SearchAndNavFormID.QuickSrchID.value != "") " line.

Here's my ascx source:

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="DTS_SearchAndNav.ascx.cs"
Inherits="DTS_UI.Components.DTS_SearchAndNav"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<script language="javascript">
function ToggleSelectBox()
{
if (SearchAndNavFormID.QuickSrchID.value !=
""){SearchAndNavFormID.ViewTypeID.disabled = true;}
else {SearchAndNavFormID.ViewTypeID.disabled = false;}
}
</script>
<div align="center" style="BORDER-TOP:black 1px solid; MARGIN-TOP:5px;
MARGIN-BOTTOM:5px; PADDING-BOTTOM:3px; WIDTH:400px; PADDING-TOP:1px;
BORDER-BOTTOM:black 1px solid;>
<div id="tommy" align="center" style="filter:alpha(starty=0,
finishy=100, startx=0, finishx=0, opacity=60, finishopacity=100,
style=1); WIDTH:400px; BACKGROUND-COLOR:#A0A0D0">
<form name="SearchAndNavForm" id="SearchAndNavFormID"
action="DTSList.aspx" method="post" style="margin:0px, padding:0px">
<small style="FONT-SIZE:9px; Color:#000000">Quick Search
&nbsp;<input onblur="ToggleSelectBox()" type="text" name="QuickSrch"
id="QuickSrchID" style="MARGIN-TOP:2px; FONT-SIZE:11px; WIDTH:140px;
BACKGROUND-COLOR:white"><span style="WIDTH:1px"></span></small>
<select ID="ViewTypeID" name="ViewType" style="FONT-SIZE:9px;
WIDTH:106px; BACKGROUND-COLOR:white">
<option <%if ((Session["gl_ViewType"] as string).ToLower() ==
"newreqs"){Response.Write("selected");};%> value="NewReqs"
style="FONT-WEIGHT:800" selected>New Requests</option>
<option <%if ((Session["gl_ViewType"] as string).ToLower() ==
"myreqs"){Response.Write("selected");};%> value="MyReqs"
style="FONT-WEIGHT:800">My Requests</option>
<option <%if ((Session["gl_ViewType"] as string).ToLower() ==
"mywishreqs"){Response.Write("selected");};%> value="mywishreqs"
style="FONT-WEIGHT:800">My Wish List</option>
<option <%if ((Session["gl_ViewType"] as string).ToLower() ==
"wishreqs"){Response.Write("selected");};%> value="wishreqs"
style="FONT-WEIGHT:800">Main Wish List</option>
<option <%if ((Session["gl_ViewType"] as string).ToLower() ==
"exreqs"){Response.Write("selected");};%> value="exreqs"
style="FONT-WEIGHT:800">Other Requests</option>
</select>
<input type="submit" value="GO" style="MARGIN-TOP:2px;
FONT-SIZE:9px; WIDTH:23px; BACKGROUND-COLOR:white" ID="SubmitBtnID"
NAME="SubmitBtn">
<br>
<input type="button" onclick="location.href='DTSSearch.asp'"
style="MARGIN-TOP:2px; FONT-SIZE:9px; WIDTH:214px;
BACKGROUND-COLOR:white"
value="Advanced Request Search"> <span
style="WIDTH:1px"></span><input type="button"
onclick="window.open('DTSNewReqWiz.asp','NewReqWin','width=350,height=250,toolbars=no,statusbar=no')"
style="MARGIN-TOP:2px; FONT-SIZE:9px; WIDTH:133px;
BACKGROUND-COLOR:white" value="New Request Wizard">
</div>
</div>
</form>
 
E

Erwin Moller

Luminousc said:
I get the dreaded, 'is null or not an object' at runtime. This happens
on the:
" if (SearchAndNavFormID.QuickSrchID.value != "") " line.

Well, that code gives me a headache too. :p

In general: Do a sanitycheck.
It helps me always when confused

So before the 'if':
alert ("SearchAndNavFormID = "+SearchAndNavFormID);
alert ("SearchAndNavFormID.QuickSrchID = "+SearchAndNavFormID.QuickSrchID);

What does that say?
Is it what you expect?
Maybe some double names?

Good luck.

Regards,
Erwin Moller
 
M

Mick White

Luminousc said:
I get the dreaded, 'is null or not an object' at runtime. This happens
on the:
" if (SearchAndNavFormID.QuickSrchID.value != "") " line.
[snip]
if (document.getElementById("QuickSrchID").value != "")

or assign names to your form and its elements:

document.forms["formName"].elements["elementName"].value

Mick
 
L

Luminousc

Yeah, tried that, I had scope of the both the Form and the fields in
the IDE, but at the page level only the form was visible.

I ended up short circuiting the issue and writing the javascript
directly into the onblur command:

onblur="if (QuickSrchID.value != ''){ViewTypeID.disabled=true;
ViewTypeID.selectedIndex=ViewTypeID.length-1;}else{ViewTypeID.disabled=false;}"

Don't know why it works there, but moving it to a separate function
and adding the 'SearchAndNavFormID.' to the front doesn't but it
doesn't matter now. This method isn't as elegant but it works.

Thanks guys for your ultra-fast answers, I posted this query in Google
Groups and had to wait until it appeared before I could post my
response.

Craig
 
E

Erwin Moller

Luminousc said:
Yeah, tried that, I had scope of the both the Form and the fields in
the IDE, but at the page level only the form was visible.

I ended up short circuiting the issue and writing the javascript
directly into the onblur command:

onblur="if (QuickSrchID.value != ''){ViewTypeID.disabled=true;
ViewTypeID.selectedIndex=ViewTypeID.length-1;}else{ViewTypeID.disabled=false;}"

Ok, good you fixed it.
Don't know why it works there, but moving it to a separate function
and adding the 'SearchAndNavFormID.' to the front doesn't but it
doesn't matter now. This method isn't as elegant but it works.

Thanks guys for your ultra-fast answers, I posted this query in Google
Groups and had to wait until it appeared before I could post my
response.

Download a newsreader.
Much more comfortable than googlegroups.
:)
Some popular choices:

On GNU/Linux: (I use KNode)
On W$: chek this:
http://www.newsreaders.com/win/clients.html

When I am on W$-box I use Agent:
get it here:
http://www.forteinc.com/agent/index.php

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top