How do I access the DOM objects using javascript.

S

Steve Kershaw

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
 
S

Steve Kershaw

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
 
S

Steve Kershaw

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"
 
V

Vlad Iliescu

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

Steve C. Orr [MVP, MCSD]

Look closer. The server side code is generating the client side code.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top