'Undefined' Client-Side Object Reference

F

Felipe

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!
 
J

John Saunders

Felipe said:
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?
 
T

Tee

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.
 
F

Felipe

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 said:
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 said:
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!
 

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

Top