How to access form objects of multiple forms in JavaScript?
I am very new to the JavaScript. I have started doing the JavaScript before the couple of weeks. I have done many basic scripting. I know to access form objects of the single form. But I don't know same thing when multiple forms are considered. So please anyone can tell me how to access form objects of multiple forms in JavaScript. Help me as soon as possible.!!:notworthy
Re: How to access form objects of multiple forms in JavaScript?
You should know one thing which is very basic. When you want to access a form through JavaScript, you will need to obtain a reference to the form object. You can do this by using the method called getElementById. Lets take an example, form with the id attribute "intro_frm", you could access the form in the following way :
Code:
var oForm = document.getElementById('intro_frm');
Hope you got the basic point of the using the getElementById method.
Re: How to access form objects of multiple forms in JavaScript?
I would like to suggest you that before going for the coding you should clear the concept. Once your concept is cleared you can access form objects from any number of forms. If you want to access multiple Forms through Javascript, you should use the this.form property. If you pass this.form to the onClick event handler of a form button, this function would get the reference to the form object. Just glance at the following code :
HTML Code:
<form name ="webpages_load" action="#">
Page Title: <input type="text" name="page_title" size="35">
Page URL: </label><input type="text" name="page_url" size="120">
Tags (comma separated): <input type="text" name="tags_list" size="40">
<input type="button" name="submit" value="Save Bookmark" onclick="showElements(this.form);">
</form>
Re: How to access form objects of multiple forms in JavaScript?
You can also access multiple Forms using the document object's forms collection. The property named forms which is a javascript array that holds references to all the form objects on the page is the property of the document object of a web page. For example, if you are having two forms, "submit_bill" and the other "submit_tax" which are appearing on a web page in this order, then you can access the form named "submit_tax" in the following two ways :
Quote:
var oForm = document.forms[1]; OR
var oForm = document.forms["submit_tax"];
Re: How to access form objects of multiple forms in JavaScript?
The following code implements the function by passing the names of the two forms. Here is the code for that :
HTML Code:
<a href="#" onClick=" javascript: copyFormElementToElementOfDifferentForm('submit_bill', 'submit_tax', 'site_cat', 'tags_list');"
>Copy site_cat element value of the first form to the input field named "tags_list" of the second form</a>