How can we help you?
Services by business type
Latest articles
Category: PHP tutorials
Go backThis tutorial will explain how to create a dropdown menu using function which populates values from the array.
This tutorial will explain how to create a dropdown menu using function which populates values from the array.
To start with create new page and within the body of this page type the following:
Now at the top of the document, before the DOCTYPE, within the php tags create two arrays – one for counties and the other one for ´how did you hear about us´: (make sure the code starts with <?php and ends with ?>
$county = array (´Kent´,´West Susses´,´East Sussex´,´Sommerset´,´Hampshire´,´London´,´Essex´); $hear = array (´Google´,´Other Search Engine´,´Magazine´,´Recommendation´);
These arrays store values which will be populated to our dropdown menus.
Now we are going to create a function which will take to parameters – name of the array and name of the form element. This function will use foreach loop to display all values from the specific array.
After $hear array type:
function createDropdown($arr, $frm) {
echo '';
}
Now go back to our form and after the line which reads:
<form id="form1" name="form1" method="post" action="">
type:
What´s happened here is we have created labels for the dropdown menus and placed createDropdown() function against them to generate dropdown menus with the values populated from the relevant array. Name of the array is passed via function´s first parameter ($county) and the name of the form element is passed as a second parameter (´frmcounty´).
Save the file and test it in the browser.
This way we can effectively use one function to handle all of the dropdown menus within our form.
Category: PHP tutorials
Go backAll rights reserved © Website Design Company :: Core Media Design Limited 2004 – 2010
Core Media Design Limited is registered in England No 6557241
Explore in further details…
And other…
Social bookmarks