Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  70] [ 4]  / answers: 1 / hits: 27968  / 12 Years ago, thu, june 14, 2012, 12:00:00

Is there a difference between this.form and document.forms (document[forms]) or, are they similar?



Here is the code I wrote to test the difference.



<form name=myForm id=myForm>
<input type=text name=haha id=myForm value=laughable onclick=alert(this.form.haha.value) />
</form>

alert(document.forms.myForm.haha.value);


They both result in the same thing.


More From » forms

 Answers
2

this.form will give you the form of the form element. (this is the form element)




The containing form element, if this element is in a form.




document.forms will give you all the forms in the document (if it's supported!)




forms returns a collection (an HTMLCollection ) of the form elements within the current document.




Better use document.getElementById(id)



var form = document.getElementById(formId);

[#84890] Thursday, June 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blaisep

Total Points: 748
Total Questions: 95
Total Answers: 108

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
blaisep questions
Wed, Dec 16, 20, 00:00, 4 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
Tue, Nov 12, 19, 00:00, 5 Years ago
Mon, Nov 11, 19, 00:00, 5 Years ago
;