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

Seeking to create websites and seo, Looking to create websites and SEO (Par...

Looking to create websites and SEO (Partnership) We want a Team of Web Development, Designing as well as SEO for Profit sharing partnership. Please read the full explanation

Draw layer from common toolbar, Step 1:  Select Layer from Common toolbar &...

Step 1:  Select Layer from Common toolbar & draw a layer. Step 2:  Write the text within the Layer. Step 3:  Click on Modify button (when the layer is selected) Step 4:  C

Need multi-language website of a retirement resort project, Multi-language ...

Multi-language website of a retirement resort project. I am seeking a website developer for a retirement resort project with the end in view of marketing the resort to worldwide

A php and ecommerce expert needed, A PHP/eCommerce Expert Needed Descrip...

A PHP/eCommerce Expert Needed Description- This is aid with an ecommerce site using Balanced payments API. There is as well certain low level PHP that will need to be done. T

Wordpress plugin configuration as well as customizations, Wordpress Plugin ...

Wordpress Plugin Configuration as well as Customizations I want help configuring a plugin correctly (Social Review Engine Plugin) in my Wordpress site. The plugin is previously

Textarea element in a form, Set the element's dimensions using row & column...

Set the element's dimensions using row & column attributes in the textarea tag so the data entered is easily viewable.  The element of course requires an appropriately descriptive

Oop, how to know object oriented in php

how to know object oriented in php

We need help to edit php code, We need help to edit php code Website wan...

We need help to edit php code Website wants editing and support in php Change notifications,logins as well as some other functionalities. Project to be discussed in more detail.

Html tag, As illustrated in Figure., is a starting tag. To delimit the tex...

As illustrated in Figure., is a starting tag. To delimit the text inside, add closing tag by a "/" to the starting tag. Most but not all tags contains a closing tag. I

Psd to pure html5 tweaks on already designed site, PSD to Pure HTML5 Tweaks...

PSD to Pure HTML5 Tweaks on already designed site I have HTML previously converted just have to fix design. Its a few hours job for you as well as only good HTML5 developers are

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