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

Formatting of text, Text formatting, in other terms presenting the text on ...

Text formatting, in other terms presenting the text on an HTML page in a wanted manner, is significant part of developing a web page. Let us understand how we can lay out of text c

We want a talented team to make a specific mobile app, Tailor made app user...

Tailor made app user tracking tool We want a talented team to make a specific mobile app tracking tool to track all events for each of our clients inside our app. You should hav

I want a simple joomla website built, I want a simple Joomla website built ...

I want a simple Joomla website built I want a developer/development team to build me a simple Joomla website with a custom design. The design will be copied EXACTLY from my curr

We need help in online map indicating locations of web page, We need help i...

We need help in online map indicating locations of web page visitors Seeking someone who can program a global map that indicates the locations of visitors for a 24-hour period (

We are looking for a developer of responsive website, Looking for someone t...

Looking for someone to make my blog responsive on all devices Job Description- We are looking for a Web Developer. Your responsibilities- a) Review business requirements

I need snell program, We sell products but now need a program prepared that...

We sell products but now need a program prepared that will take clients serial numbers from products purchased and link it to our website or stand alone software and it alerts clie

I am in need of flash video streaming expert, I am in need of Flash Video S...

I am in need of Flash Video Streaming expert I own a premium PHP, MySQL as well as Adobe Flash video chat room website. I want someone with real experience that can make improve

Wix commerce site needs shopping backend integration, WIX commerce site nee...

WIX commerce site needs 1shopping backend integration Project Description: We sell children's furnitureRIEchildrensFurniture and want a robust backend integrated shopping car

Design a website in wordpress, Website using Wordpress I'm looking for s...

Website using Wordpress I'm looking for someone to design a website for me. I have example websites of what I'm looking for. Design Type: New Website Purpose of the Web

Make a page with a form which can be submitted on our phpbb, Make a page wi...

Make a page with a form which can be submitted on our Phpbb forum We consists a website with a Phpbb forum on it and we want to have a page created on the forum where people tha

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