[Javascript] javascript and id's

Flavio Gomes flavio at economisa.com.br
Tue Oct 4 11:53:28 CDT 2005


Having a form named* "myForm" and an input named "myInput":
 You can access it by "document.myForm.myInput" in the majority of the 
browsers.

* Yeah, by "named" I mean giving the "name" atribute a value.

<form name=myForm action=processStuff.html>
  <input type=text name=myInput value="Enter Text" />
  <input type=submit name=mySubmit value="Go" />
</form>

<script language="JavaScript">
  alert(document.myForm.myInput.value);

  document.myForm.myInput.onkeydown = function () {window.status=this.value}
</script>

-- 
Flavio Gomes
flavio at economisa.com.br



Anthony Ettinger wrote:

>Ok, so I have a <form id="foo">
>
>Is this the best way to access descendents of <form>?
>By keying off the ancestor, and then looping through
>it's elements?
>
>Or should I give each form element it's own id...
>
>I want to change the value of an attribute of an input
>field:
>
><input type="text" name="foo">
>
>want to change it to 
>
><input type="text" name="bar">
>
>
>What I ended up doing was giving the <input> element
>an id="searchfield", and then looping through it's
>attributes using '.attributes' on the input object,
>and testing the name of the attribute == 'name'. and
>then replacing it's value with 'bar'.
>
>Is there an easier way to access an attribute of an
>element if I know it's direct path?
>
>Seems to me very inefficient to have to do looping if
>it's not necessary.
>
>Anthony Ettinger
>ph: (408) 656-2473
>blog: http://www.chovy.com
>
>
>		
>__________________________________ 
>Yahoo! Mail - PC Magazine Editors' Choice 2005 
>http://mail.yahoo.com
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
>  
>




More information about the Javascript mailing list