Difficulty: Moderately Easy
Things You’ll Need:
- Notepad
- Hosting account with PHP
- FTP (if no file manager is provided)
Step1
The first thing we need to do is create a new document, I'll be using DreamWeaver CS3, but you can use your favorite text editor; Notepad will be fine.
Now we need to write some code. We are going to create our function GetStats() and put all the code inside it.
Step2
Image depicting the function and array already in our code.
The states are going to be inside an array, this will help us loop through each, one at a time using a foreach loop.
Step3
Foreach loop in action.
Next all we need to do is cycle through each state in the array using a foreach loop and create the necessary HTML code for it. Note that we only want to repeat the options code, which is why that's the only HTML inside our loop.
The select portion of the HTML code is left outside the loop, otherwise it would create a Drop Down List for every state and we don't want that to happen here.
Step4
Image depicting how the function looks at the end.
This is how the function should look like in your code in order to work correctly. Don't forget to call the function where you want the drop down list to appear like this: GetStates();
Comments
mbsan4 said
on 11/14/2007 This a great article, very helpuful! thank you!
mbsan4 said
on 11/14/2007 This a great article, very helpuful! thank you!