javascript: variable form names.

Results 1 to 2 of 2

Thread: javascript: variable form names.

  1. #1
    Join Date
    Dec 1969

    Default javascript: variable form names.

    I am trying to call an action on a string that has a variable form name. <BR>Everything works fine when I hard code the name form name but when I use a variable nothing happens.<BR><BR>Form name = &#039;myForm&#039;<BR>Variable name = &#039;theForm&#039;<BR><BR>myForm.formName.valu e = theForm; ---- Works<BR>theForm.formName.value = theForm; ---- Does Not work<BR><BR>I also tried<BR><BR>elements[theForm].formName.value = theForm;<BR><BR>but that does not work either.<BR><BR>Any ideas?<BR><BR>MTmace

  2. #2
    Join Date
    Dec 1969

    Default document.forms[theForm]

    document.SOMEFORMNAME.elements[ ] is the array of form elements.<BR><BR>document.forms[ ] is the array of forms.<BR><BR>You can use either numeric *or* text indexes to get individuald forms or elements, as is true in all JS arrays.<BR><BR>So:<BR> var formNameVariable = "myForm";<BR>and then *all* of these are equivalent:<BR> document.myForm.formName.value<BR> document.forms["myForm"].formName.value<BR> document.forms[formNameVariable].formName.value<BR>and if that form happens to be the first one on the page, then this is also equivalent:<BR> document.forms[ 0 ].formName.value<BR><BR>Hokay?<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts