tags:

views:

29

answers:

1

HI, I have and aspx form in which i am referring a JavaScript file. I am using the window.onload method to initialize an object. How can I get the form object inside the function in JavaScript file.

+3  A: 

Your form will be defined like so:

<form name="my_form" id="my_form"></form>

You can use the following different methods to act on the form:

var form = document.forms[0]; // Not the best choice due to hard-coding an index.
var form = document.forms["my_form"]; // Retrieves the form by name
var form = document.getElementById("my_form"); // Retrieves by ID.
jthompson