Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > 'Undefined' Client-Side Object Reference

Reply
Thread Tools

'Undefined' Client-Side Object Reference

 
 
Felipe
Guest
Posts: n/a
 
      07-15-2004
In the HTML portion of an ASPX page, I have the following:

<INPUT TYPE=TEXT SIZE=2 NAME=VSpace onchange="Img_Preview()"
ONKEYPRESS="event.returnValue=IsDigit();" style="width:80px;" ID="VSpace">

Note that the <INPUT> control calls Img_Preview().

Img_Preview, amongst other things, executes this next line:

var VSpace = document.getElementById("VSpace");

When the value of VSpace is subsequently check, it is "undefined":

alert("VSpace.value=[" + VSpace2.value + "]"); // When this line is
executed, the word 'undefined' appears inside the brackets. Why?

The confusing part is that it all works in another page (same machine)... I
have studied the two pages and have not been able to identify the relevant
differences.

Any help is greatly appreciated!


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      07-16-2004
"Felipe" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In the HTML portion of an ASPX page, I have the following:
>
> <INPUT TYPE=TEXT SIZE=2 NAME=VSpace onchange="Img_Preview()"
> ONKEYPRESS="event.returnValue=IsDigit();" style="width:80px;" ID="VSpace">
>
> Note that the <INPUT> control calls Img_Preview().
>
> Img_Preview, amongst other things, executes this next line:
>
> var VSpace = document.getElementById("VSpace");
>
> When the value of VSpace is subsequently check, it is "undefined":
>
> alert("VSpace.value=[" + VSpace2.value + "]"); // When this line is
> executed, the word 'undefined' appears inside the brackets. Why?


Perhaps the onchange event fires before the value is updated to reflect the
change?
--
John Saunders
johnwsaundersiii at hotmail


 
Reply With Quote
 
 
 
 
Tee
Guest
Posts: n/a
 
      07-16-2004
I'm not really sure what caused the problem.
But I think you need to change the document.getElementById("VSpace") to
document.all['VSpace']

not sure if this would work, but worth a try at least.




"Felipe" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In the HTML portion of an ASPX page, I have the following:
>
> <INPUT TYPE=TEXT SIZE=2 NAME=VSpace onchange="Img_Preview()"
> ONKEYPRESS="event.returnValue=IsDigit();" style="width:80px;" ID="VSpace">
>
> Note that the <INPUT> control calls Img_Preview().
>
> Img_Preview, amongst other things, executes this next line:
>
> var VSpace = document.getElementById("VSpace");
>
> When the value of VSpace is subsequently check, it is "undefined":
>
> alert("VSpace.value=[" + VSpace2.value + "]"); // When this line is
> executed, the word 'undefined' appears inside the brackets. Why?
>
> The confusing part is that it all works in another page (same machine)...

I
> have studied the two pages and have not been able to identify the relevant
> differences.
>
> Any help is greatly appreciated!
>
>



 
Reply With Quote
 
Felipe
Guest
Posts: n/a
 
      07-16-2004
Thank you John and Tee for your ideas... I finally figured it out... it was
an issue specific to my code and not to JavaScript syntax... defaults were
not assigned properly on Postback. That is, life was good when the page
first opened, but when a postback occured, the HTML control was assigned the
value of an uninitialized variable (var somevar... so I initialized the
variable at the time of definition (var somevar="" and that took care of
the problem.




"Tee" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm not really sure what caused the problem.
> But I think you need to change the document.getElementById("VSpace") to
> document.all['VSpace']
>
> not sure if this would work, but worth a try at least.
>
>
>
>
> "Felipe" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > In the HTML portion of an ASPX page, I have the following:
> >
> > <INPUT TYPE=TEXT SIZE=2 NAME=VSpace onchange="Img_Preview()"
> > ONKEYPRESS="event.returnValue=IsDigit();" style="width:80px;"

ID="VSpace">
> >
> > Note that the <INPUT> control calls Img_Preview().
> >
> > Img_Preview, amongst other things, executes this next line:
> >
> > var VSpace = document.getElementById("VSpace");
> >
> > When the value of VSpace is subsequently check, it is "undefined":
> >
> > alert("VSpace.value=[" + VSpace2.value + "]"); // When this line is
> > executed, the word 'undefined' appears inside the brackets. Why?
> >
> > The confusing part is that it all works in another page (same

machine)...
> I
> > have studied the two pages and have not been able to identify the

relevant
> > differences.
> >
> > Any help is greatly appreciated!
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What to return -- object, reference or const reference Arv C++ 15 03-07-2008 09:15 PM
"Object reference not set to an instance of an object" Weird thing happens with reference a link nguyentrongkha@gmail.com ASP .Net 1 09-20-2007 09:46 PM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
ASP.NET 2.0: master pages and web user controls: reference to a non-shared member requires an object reference bminder ASP .Net 0 06-24-2005 12:22 AM
asp.net 2005 question re: "reference to a non-shared member requires an object reference" ce ASP .Net 1 06-23-2005 09:15 PM



Advertisments