simonslater Posted March 24, 2009 Share Posted March 24, 2009 Hello all, As you probably can ascertain from my question I am PHP neophyte. I trying to make a for where the form elements sit in a html table. The problem I have is that I created a dynamic drop down menu item as a function and everytime i set it is a cell in the html table it will not sit in the cell. Instead the dropdown menu sits in the upper right hand corner of the browser. The code for the drop down function is: function drop_down_menu($content, $name) { //dynamic drop down menu component. Has stored common month //day year settings. An array of content can be passed as well. //established menu values $states = array('AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'); $weekdays = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); $month = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $number = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'); $default = array('Hey', 'Dude!','you', 'have', 'not', 'set', 'menu', 'items'); //chooses type of content to show in drop down switch ( $content ) { case "states": $menu_content = $states; break; case "day": $menu_content = $weekdays; break; case "month": $menu_content = $month; break; case "number": $menu_content = $number; break; case NULL: $menu_content = $default; break; default: $menu_content = $content; break; } $menu_size = count($menu_content); echo '<select name ='.$name.'>'; for ( $i = 0; $i < $menu_size; $i++ ) { echo '<option>'.$menu_content[$i].'</option>'; } echo '</select>'; } ?> The form code is: echo ' ----------------------------------------- <h1>Enter Information</h1> <center> <form action"'.$_SERVER["PHP_SELF"].'" method="GET"> <table border=0 cellspacing=10 cellpadding=0 bgcolor="FFCCCC"> <tr> <td> <label> First Name: <input type="text" name="firstname" /> </label> </td> <td> <label> Last Name: <input type="text" name="lastname" /> </label> </td> </tr> <tr> </tr> <tr> <td> <label> Email: <input type="text" name="email" /> </label> </td> <td> <label> Phone: <input type="text" name="phone" /> </label> </td> <td> </td> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> <td> <b><i>Location Info:</i></b> </td> </tr> <tr> <td> <label>Address: <input type="text" name="startadd" /> </label> </td> <td> <label>City: <input type="text" name="startcity" /> </label> </td> </tr> </td> </tr> <tr> </tr> <tr> <td> <label>State:'.drop_down_menu().'</label> <input type="submit" value="Go!" /> </td> </form></center>' Any help is much appreciated. -Simon Slater Link to comment https://forums.phpfreaks.com/topic/150805-cannot-get-a-function-to-sit-in-a-html-table/ Share on other sites More sharing options...
trq Posted March 24, 2009 Share Posted March 24, 2009 Change this.... echo '<select name ='.$name.'>'; for ( $i = 0; $i < $menu_size; $i++ ) { echo '<option>'.$menu_content[$i].'</option>'; } echo '</select>'; } to.... $out = '<select name ='.$name.'>'; for ( $i = 0; $i < $menu_size; $i++ ) { $out .= '<option>'.$menu_content[$i].'</option>'; } $out .= '</select>'; return $out; } Your function calls echo yet your using it within an echo statement. Link to comment https://forums.phpfreaks.com/topic/150805-cannot-get-a-function-to-sit-in-a-html-table/#findComment-792271 Share on other sites More sharing options...
simonslater Posted March 24, 2009 Author Share Posted March 24, 2009 Thank you very much! Works like a charm! Regards, Simon Link to comment https://forums.phpfreaks.com/topic/150805-cannot-get-a-function-to-sit-in-a-html-table/#findComment-792321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.