Javascript in Web Parts and DOM

G

Guest

How do use Javascript within a Web Part to set a document.form item's value,
etc.? As in, document.forms[0].myTextBox. value = "abc"; Since the html form
is not within the web part, this does not work.
 
L

Laurent Bugnion [MVP]

Hi,
How do use Javascript within a Web Part to set a document.form item's value,
etc.? As in, document.forms[0].myTextBox. value = "abc"; Since the html form
is not within the web part, this does not work.

Use document.getElementById.

Note however that the ID on the client (web browser) is set
automatically by ASP.NET, based on the control's ID and its container
ID. To make sure that you get the correct ID, use ClientID

In the code behind:

"document.getElementById( '" + myTextBox.ClientID + "' ).value = 'abc';"

HTH,
Laurent
 

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

Top