DamianWarS
07-06-2009, 10:45 AM
What is the best way for me to access a form field in JavaScript. Lets say for example I have a form with the name of "myForm" and I want to set the value of the first form field which is a textbox called "myTextBox" (both ID and Name) to "Hello World!"
document.myForm.myTextBox.value="Hello World!";
document.forms[0][0].value="Hello World!";
document.forms["myForm"]["myTextBox"].value="Hello World!";
document.getElementById("myTextBox").value="Hello World!";
or whatever other combination of the above you can have. If you have a better way of doing it then list that as well. Currently I am using the first example.
document.myForm.myTextBox.value="Hello World!";
document.forms[0][0].value="Hello World!";
document.forms["myForm"]["myTextBox"].value="Hello World!";
document.getElementById("myTextBox").value="Hello World!";
or whatever other combination of the above you can have. If you have a better way of doing it then list that as well. Currently I am using the first example.