ASP.Net 1.1 Client Script

G

Guest

I have an asp.net page with client side javascript. In the script I can get
a control and read its properties by using
document.getElementById('txtDBName'). But if I try to set any of the
properties of this control it doesn't work; for example the code line
document.getElementById('txtDBName').value = 'hosted';. Can anyone explain
why this is.

I have other pages where I do the same thing in client javascript and those
pages work fine but on this one page this doesn't work. I have compared
pages and I see no differences in the page that doesn't work and the page
that does work.
 
G

Guest

The statement document.getElementById('txtDBName').value = 'hosted'; would
fail to produce an outcome if there were no control with that ID found. This
could happen if you are referring to a server control that is within another
server control (e.g. a textbox within a datagrid) where the ClientID would
look like this: datagrid1:txtDBName.

Try always to check if the getElementById function returned a null or an
object, e.g.
var txtBox = document.getElementById('txtDBName');
if (txtBox!=null)
{
txtBox.value = "hosted";
}
else
{
alert("could not find a textbox with id='txtDBName'" );
}
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top