By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

Output array values using function

P: 2
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $county = array (´Kent´,´West Susses´,´East Sussex´,´Sommerset´,´Hampshire´,´London´,´Essex´);
  3. $hear = array (´Google´,´Other Search Engine´,´Magazine´,´Recommendation´);
  4.  
  5. function createDropdown($arr, $frm) {
  6.  
  7. echo '<select name="'.$frm.'" id="'.$frm.'"><option value="">Select one…</option>
  8. <option value="'.$value.'">'.$value.'</option></select>';
  9.  
  10. }
  11.  
  12. ?>
  13.  
  14.  
  15. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  16. <html xmlns="http://www.w3.org/1999/xhtml">
  17. <head>
  18. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  19. <title>Untitled Document</title>
  20. </head>
  21.  
  22. <body>
  23.  
  24. <form  id="ddown" name="ddown" method="post" action="createDropdown.php"></form>
  25. <label  for="frmcounty">County:</label>
  26.  
  27. <label  for="frmhowhear">How did you hear about us?:</label>
  28.  
  29.  
  30.  
  31.  
  32.  
  33. </body>
  34. </html>
Apr 1 '10 #1
Share this Question
Share on Google+
3 Replies


chathura86
100+
P: 227
change the function to this

Expand|Select|Wrap|Line Numbers
  1. function createDropdown($arr, $frm) {
  2.  
  3.     echo '<select name="'.$frm.'" id="'.$frm.'">';
  4.  
  5.     echo '    <option value="">Select one…</option>';
  6.  
  7.     foreach ($arr as $value)
  8.         echo '<option value="'.$value.'">'.$value.'</option>';
  9.  
  10.     echo '</select>';
  11.  
  12. }
  13.  
to use it

Expand|Select|Wrap|Line Numbers
  1. <?php createDropdown($county, 'selCountry'); ?>
  2.  
put the above code where you want the dropdown

Regards
Chathura Bamunusinghe
Apr 1 '10 #2

P: 2
Thank you Chathura Bamunusinghe .

It's really work!i hope u don't mind to guide me if i need help from you. :)

-bubblediana-
Apr 5 '10 #3

chathura86
100+
P: 227
sure that's what bytes is for.

post your problems here and me or some one else will
try to assist you.

and please mark the best answer when ever you can, because it
will help other to find the solution

Regards
Chathura Bamunusinghe
Apr 5 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.