Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

beginner question

Status
Not open for further replies.

Nanda

Programmer
Nov 14, 2000
104
US
Hi all!
I have a very a basic question... How can I refer to a document element from my Javascript?
...everytime i need to do hit and trials to find how do I access/set an elements of document...like what is correct...

document.forms.my_form.my_list.value
document.all.tags("button").name
document.tags("input").value
document.tags("select").value

really do not know when to use what??

Thanks
 
elements!

so

document.formname.elements["elementname"].value
*or*
document.forms["formname"].elements["elementname"].value
*for it to work in Netscape!

so:
document.forms["my_form"].elements["my_list"].value

you can access all the controls properties this way - including the name, type etc. etc.

Hope that helps.

 
Thanks Mzongo. Making sense to me now.

What if I do not have form. OR I have array of controls?
 
if you have an array of controls, for instance: elements["my_list"] where my_list is an array, you can use a variable.
Like: document.forms["my_form"].elements[x].value
Well, you need a form in order to use the submit function. But if you don't have a name, you can just say:
document.form.elements[x].value
Hope that helps any...

I have not failed; I merely found 100,000 different ways of not succeding...
 
Nanda,
why not document.forms.formname.elementname.value ?
i mean ur first line.. :) must be workin Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top