Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Three newbie questions

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Three newbie questions
1.
a. var aField = myForm['aField'];
b. var aField = myForm.document.getElementById('aField')
what is the difference between the two ?

2. Does JS string have same function as aString.trim() in java ?

3. Where can I find some mature JS utility package, just like jar component in Java ?

Thanks for your help.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.
a. var aField = myForm['aField'];
b. var aField = myForm.document.getElementById('aField')
what is the difference between the two ?

getElementnById is a DOM method to find an element by its id. Ids have to be sigular so you can not have more than one element on the page with that id. The other references the form object for a name, names can be repeated on a page! IE is bad and allows for name to be seached by getElementById, but no other browsers allow that. So do not do it! Just a warning!

var myElem = document.forms["name or index number"].elements["name or index number"] is the full way to reference an element with the form object array and element array.

2. Does JS string have same function as aString.trim() in java ?
No, but you can add this to your funcitons and it adds the functionality to the string object:



3. Where can I find some mature JS utility package, just like jar component in Java ?
Guess you are asking for a library? Look for prototype.js (Google should be first result)

Eric
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic