Home All Groups Group Topic Archive Search About

Javascript in Web Parts and DOM

Author
2 Feb 2007 3:12 AM
dhmason
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.

Author
2 Feb 2007 3:05 PM
Laurent Bugnion [MVP]
Hi,

dhmason wrote:
> 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
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

AddThis Social Bookmark Button