rockindano30 Posted April 10, 2008 Share Posted April 10, 2008 im working on a drop down menu. now i know its simple but i can't seem to make it work. its a menu with four selections. and when one is selected i want it to display info right below it in the same page. code is as follows: <?php print "<select name='find'>"; print "<option value='a'>Central Fire Station</option>"; print "<option value='b'>Fire Station 2</option>"; print "<option value='c'>Fire Station 3</option>"; print "<option value='d'>Fire Station 4</option>"; print "</select>"; $find=$_POST['find']; if ($find == 'a') print "central station"; elseif($find == 'b') print "station number 2"; elseif ($find == 'c') print "station number 3"; elseif ($find == 'd') print "station 4"; ?> help please............. Quote Link to comment https://forums.phpfreaks.com/topic/100515-solved-drop-down-menu-help/ Share on other sites More sharing options...
craygo Posted April 10, 2008 Share Posted April 10, 2008 in order to do it you have to submit the dropdown menu to the server. php is a server side language so no instand output can be done if you want instant you will have to use javascript. Quote Link to comment https://forums.phpfreaks.com/topic/100515-solved-drop-down-menu-help/#findComment-514079 Share on other sites More sharing options...
rockindano30 Posted April 10, 2008 Author Share Posted April 10, 2008 how would i submit the dropdown menu Quote Link to comment https://forums.phpfreaks.com/topic/100515-solved-drop-down-menu-help/#findComment-514084 Share on other sites More sharing options...
Zhadus Posted April 10, 2008 Share Posted April 10, 2008 You can either add a normal submit button: print "<input type='submit' value='Submit'>"; After putting the dropdown in a form, or you can use javascript to submit onchange() (Which would also require the dropdown in a <form>. Quote Link to comment https://forums.phpfreaks.com/topic/100515-solved-drop-down-menu-help/#findComment-514087 Share on other sites More sharing options...
craygo Posted April 10, 2008 Share Posted April 10, 2008 A simpler way would be to submit with javascript <?php print "<form action=\"\" method=post />"; print "<select name='find' onchange=\"this.form.submit();\" >"; print "<option value='a'>Central Fire Station</option>"; print "<option value='b'>Fire Station 2</option>"; print "<option value='c'>Fire Station 3</option>"; print "<option value='d'>Fire Station 4</option>"; print "</select>"; print "</form>"; if(isset($_POST['find'])){ $find = $_POST['find']; if ($find == 'a') print "central station"; elseif($find == 'b') print "station number 2"; elseif ($find == 'c') print "station number 3"; elseif ($find == 'd') print "station 4"; } ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/100515-solved-drop-down-menu-help/#findComment-514093 Share on other sites More sharing options...
Zhadus Posted April 10, 2008 Share Posted April 10, 2008 If you're targetting a wide audience, you should add print "<noscript><input type='submit' value='Submit'></noscript>"; Before the </form> tag for those without javascript enabled. Quote Link to comment https://forums.phpfreaks.com/topic/100515-solved-drop-down-menu-help/#findComment-514096 Share on other sites More sharing options...
rockindano30 Posted April 10, 2008 Author Share Posted April 10, 2008 Thank you guys thats what i was missing. ah........... much better now. Quote Link to comment https://forums.phpfreaks.com/topic/100515-solved-drop-down-menu-help/#findComment-514101 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.