'Undefined' Client-Side Object Reference

Discussion in 'ASP .Net' started by Felipe, Jul 15, 2004.

  1. Felipe

    Felipe Guest

    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!
     
    Felipe, Jul 15, 2004
    #1
    1. Advertising

  2. "Felipe" <> wrote in message
    news:...
    > 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
     
    John Saunders, Jul 16, 2004
    #2
    1. Advertising

  3. Felipe

    Tee Guest

    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" <> wrote in message
    news:...
    > 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!
    >
    >
     
    Tee, Jul 16, 2004
    #3
  4. Felipe

    Felipe Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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!
    > >
    > >

    >
    >
     
    Felipe, Jul 16, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fred
    Replies:
    3
    Views:
    1,094
    Bobby Ryzhy
    Jul 12, 2004
  2. Boss302
    Replies:
    0
    Views:
    1,098
    Boss302
    Nov 21, 2006
  3. Bogdan
    Replies:
    2
    Views:
    686
    Bogdan
    Jun 9, 2008
  4. Nathan Sokalski
    Replies:
    1
    Views:
    737
    Alexey Smirnov
    Apr 13, 2009
  5. Zoe Hart
    Replies:
    1
    Views:
    401
    Scott Wisniewski
    Jan 8, 2004
Loading...

Share This Page