Javascript in Web Parts and DOM

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
Back
Top