Forms, PHP Web Programming

Assignment Help:

Each of form in a document develops a form object. As a document can have more than one form, Form objects are stored in an array called forms.

Forms Array

By using the forms[ ] array we access each of the Form object in turn and illustrates the value of its name property in message box. Let us have a look at an instance that uses the forms array. Here we have a page along three forms on it.

<HTML>                                                                                                                                          

<HEAD>                                                                                                                                            

<SCRIPT LANGUAGE=JavaScript>                                                                                         

function window_onload()                                                                                                           

{                                                                                                                                                   

var numberForms = document.forms.length;                                                                          

var formIndex;                                                                                                                          

for (formIndex = 0; formIndex < numberForms; formIndex++)                                          

{                                                                                                                                               

alert(document.forms[formIndex].name

}                                                                                                                                                

}         

</SCRIPT>

</HEAD>                                                                                                                                           

<BODY LANGUAGE=JavaScript onLoad="window_onload()">                                               

<FORM NAME="form1">                                                                                                        

<P>This is inside form1</P>

</FORM>                                                                                                                                   

<FORM NAME="form2">                                                                                                      

<P>This is inside form2</P>

</FORM>                                                                                                                                    

<FORM NAME="form3">                                                                                                     

<P>This is inside form3</P>                                                                                          

</FORM>                                                                                                                                   

</BODY>                                                                                                                                          

</HTML>         

In the body of the page we define three forms. Each of the form is provided name, and contains a paragraph of text. In the definition of the <BODY> tag, the                               

window_onload( ) function is connected to the window object's onLoad event handler.            

<BODY LANGUAGE=JavaScript onLoad="return

window_onload( )">                                                                                                                     

This means that while the page is loaded, our window_onload() function shall be called. The window_onload( ) function is described in a script block in the HEAD of the page. In this function we loop through the forms[ ] array. Just like other JavaScript array, the forms[ ] array contain length property which we can employ to determine how several times we have to loop. In fact, as we know how many forms there are, we could just write the number in. Though, here we are also demonstrating length property, as then it is easier to add to the array without change the function. Generalizing your code such as is a good practice to follow.                      

.

The function begins through getting the number of Form objects in the forms array & stores it in the variable numberForms.

function window_onload( )

{

var numberForms = document.forms.length;

After that we define a variable, formIndex, to be utilized in our for loop. After this comes for loop itself.

for (formIndex = 0; formIndex < numberForms; formIndex++)

{

alert(document.forms[formIndex].name);

}

Keep in mind that as the indices for arrays begins at zero, our loop have to go from an index of 0 to index of number Forms - 1. We do this through initializing the formIndex variable to zero, & setting the condition of for loop to formIndex < numberForms.

In the for loop's code, we pass the index of the wished form (i.e., formIndex) to document.forms[ ], that gives us the Form object at that array index in the forms array. To access Form object's name property, we put a dot at the ending and the name of the property, name.


Related Discussions:- Forms

Need help in magento site optimization, Need help in Magento Site Optimizat...

Need help in Magento Site Optimization and Cross Browser Compatibility Looking for Magento expert for optimization of development site due to be launched soon. Tasks would compr

Copy and modify website for writing service, Project Description: We wou...

Project Description: We would like to prepare a writing service website. We need to make it very simple > someone come to the site to purchase content for a project > client pic

We need help in financial application support, We need help in Financial Ap...

We need help in Financial Application Support Enhance our account aggregation process using Yodlee API. We want to fix several bugs in our existing process as well as change fro

I need help to convert a non responsive wordpress theme, I need help to Con...

I need help to Convert a non responsive wordpress theme to responsive Twitter Bootstrap3 My website is using a none responsive wordpress theme. I want to translate this theme in

We are need of an expert drupal developer, We are need of an expert Drupal ...

We are need of an expert Drupal Developer Immediate want for developer to finish getting our site ready for public display, working out some bugs as well as getting our site fun

I need help to build state information portal, I need help to build State I...

I need help to build State Information Portal I am looking for a complete state information portal which has information about state education, healthcare, tourism, government o

Dns server, Several computers linked to the Internet host part of the DNS d...

Several computers linked to the Internet host part of the DNS database & the software which allows others to access it. These all computers are known DNS servers. No DNS server has

Need professional website, Need professional website, backend system with l...

Need professional website, backend system with login and admin panel Project Description: we want someone or a team who are able to assist us in the subsequent, 1) a profe

Search engines, Search Engines are programs which search the web. Web is a ...

Search Engines are programs which search the web. Web is a big graph along with the pages being the nodes & hyperlinks being the arcs. Search engines gather all the hyperlinks on e

Form object, This is a property of the document object. It corresponds to a...

This is a property of the document object. It corresponds to an HTML input form constructed from the FORM tag. A form can be submitted through calling the JavaScript submit method

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd