Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do I access the DOM objects using javascript.

Reply
Thread Tools

How do I access the DOM objects using javascript.

 
 
Steve Kershaw
Guest
Posts: n/a
 
      04-26-2006
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

 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      04-27-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>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
>



 
Reply With Quote
 
 
 
 
Steve Kershaw
Guest
Posts: n/a
 
      04-27-2006
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

 
Reply With Quote
 
Steve Kershaw
Guest
Posts: n/a
 
      04-27-2006
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


 
Reply With Quote
 
Vlad Iliescu
Guest
Posts: n/a
 
      04-27-2006
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$Da taSetNameTextBox"
type="text" value="" maxlength="50"
id="ctl00_ContentPlaceHolder1_fvwNormsDataSet_Data SetNameTextBox" />
, 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.

 
Reply With Quote
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      04-27-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>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
>



 
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
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Convert a XML DOM Object to a HTML DOM Object manjunath.d@gmail.com XML 0 09-20-2005 08:16 AM
What is the difference between DOM Level 1 and DOM Level 2. mike XML 1 11-20-2004 03:19 PM
Difference between pure DOM and JAXP over DOM ?? Thorsten Meininger XML 0 07-28-2004 08:51 AM
Difference between pure DOM and JAXP over DOM ?? Thorsten Meininger Java 0 07-28-2004 08:51 AM



Advertisments