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 invoicing program to link with shopify, Invoicing program to l...

Invoicing program to link with shopify We are seeking someone to create an invoicing program that can be linked to shopify. There are several apps out there for invoicing wit

We need an experienced ruby on rails engineer, We need an Experienced Ruby ...

We need an Experienced Ruby on Rails Engineer We want a developer with very good knowledge of Ruby on Rails to stay development on a live web application. The ideal expert wi

I want php website development, I want PHP website Development (NON CMS) ...

I want PHP website Development (NON CMS) Project Description: Create a Custom Website in PHP only. Do Not Suggest any CMS for this software and not show your CMS portfolio.

Seeking a five to six page content driven website, FF-Greek Dairy Website ...

FF-Greek Dairy Website Seeking a 5-6 Page Content driven website for a diary to feature products from the store, The aptitude to edit from the back-end any pictures and product

Design and create a web site, Design and create a Web site on any topic tha...

Design and create a Web site on any topic that is of interest to you.Zip all the files that you use for your Web site and submit the zip file. Your Web site MUST have the

We need a website developer, We need a Website developer A luxury swimwe...

We need a Website developer A luxury swimwear brand is seeking a website developer to create an e-commerce website as well as mobile version. We need somebody who can host our d

Wordpress admin/programmer needed, WordPress Admin/Programmer In order t...

WordPress Admin/Programmer In order to participate please answer to the following questions- 1) What is a child theme? 2) When do you use a child theme? 3) Please give

We are seeking a web application developer, SVG Programmer SVG, CSS, AJA...

SVG Programmer SVG, CSS, AJAX, JAVA knowledge necessary Job Description: We're seeking a Web Application Developer Your responsibilities- Linking SVG element to another el

Web programmer need to integrate web and database, Web Programmer need to i...

Web Programmer need to integrate web and database Requirements- The primary responsibility of the intended web programmer is- 1) Choose as well as customize website templa

Need help to debug cs-cart installation, Need help to Debug CS-Cart install...

Need help to Debug CS-Cart installation We have a CS-Cart installed on one of our servers. The site is running as well as everything is working, except for the fact that ther

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