How do I access the DOM objects using javascript.

Discussion in 'ASP .Net' started by Steve Kershaw, Apr 27, 2006.

  1. I have a problem in that I need to access the value (text) in an
    asp:textbox using javascript. Is there any way to do this or am I all
    wet? Do I have to use VBScript to access asp: objects?

    Thanks in advance for your help!

    Steve
     
    Steve Kershaw, Apr 27, 2006
    #1
    1. Advertising

  2. It's standard HTML by the time the browser gets it, so you can use standard
    JavaScript (Or VBScript in IE) to access the DOM just as you would for any
    web page.

    Here's more info:
    http://SteveOrr.net/articles/ClientSideSuite.aspx

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net



    "Steve Kershaw" <> wrote in message
    news:...
    >I have a problem in that I need to access the value (text) in an
    > asp:textbox using javascript. Is there any way to do this or am I all
    > wet? Do I have to use VBScript to access asp: objects?
    >
    > Thanks in advance for your help!
    >
    > Steve
    >
     
    Steve C. Orr [MVP, MCSD], Apr 27, 2006
    #2
    1. Advertising

  3. I checked out the code you referenced and it all looks like server side
    code to me. None of it is javascript. I need to run a javascript
    "function" that collects the .text from the asp: textbox. But the
    javascript dosen't recognize the asp:textbox as an HTML object.

    Hmm....
    Thanks

    Steve
     
    Steve Kershaw, Apr 27, 2006
    #3
  4. In experimenting around I find that:

    <input type="text" name="mytext" > will work if I use javascript
    document.aspnetForm.mytext.value = "Hi there";

    However when the textbox is an asp: like:

    <asp:TextBox ID="TextBox1" runat="server">My text 2</asp:TextBox> will
    NOT WORK
    with javascript: window.document.aspnetForm.TextBox1.Text = "Hi
    again!";

    It gives me an error message that states:
    "window.document.aspnetForm.TextBox1 is null or not an object"

    Steve Kershaw wrote:
    > I checked out the code you referenced and it all looks like server side
    > code to me. None of it is javascript. I need to run a javascript
    > "function" that collects the .text from the asp: textbox. But the
    > javascript dosen't recognize the asp:textbox as an HTML object.
    >
    > Hmm....
    > Thanks
    >
    > Steve
     
    Steve Kershaw, Apr 27, 2006
    #4
  5. Steve Kershaw

    Vlad Iliescu Guest

    You should view the source in IE and see what id is assigned to that
    textbox. Each control is given a client-side unique id, based on its
    server-side id and the ids of its container controls.

    For example a server-side textbox with the id of DataSetNameTextBox is
    outputted as
    <input
    name="ctl00$ContentPlaceHolder1$fvwNormsDataSet$DataSetNameTextBox"
    type="text" value=":p" maxlength="50"
    id="ctl00_ContentPlaceHolder1_fvwNormsDataSet_DataSetNameTextBox" />
    , as it is contained by a formview, which is contained by a master page
    placeholder, and so on.

    As you can see, the textbox is outputted as an input, so trying to
    access the Text property will result in a javascript error.
     
    Vlad Iliescu, Apr 27, 2006
    #5
  6. Look closer. The server side code is generating the client side code.

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net


    "Steve Kershaw" <> wrote in message
    news:...
    >I checked out the code you referenced and it all looks like server side
    > code to me. None of it is javascript. I need to run a javascript
    > "function" that collects the .text from the asp: textbox. But the
    > javascript dosen't recognize the asp:textbox as an HTML object.
    >
    > Hmm....
    > Thanks
    >
    > Steve
    >
     
    Steve C. Orr [MVP, MCSD], Apr 27, 2006
    #6
    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. Thorsten Meininger
    Replies:
    0
    Views:
    453
    Thorsten Meininger
    Jul 28, 2004
  2. Thorsten Meininger
    Replies:
    0
    Views:
    522
    Thorsten Meininger
    Jul 28, 2004
  3. mike
    Replies:
    1
    Views:
    1,268
    Martin Honnen
    Nov 20, 2004
  4. 7stud
    Replies:
    11
    Views:
    730
    Dennis Lee Bieber
    Mar 20, 2007
  5. SM
    Replies:
    3
    Views:
    125
Loading...

Share This Page