Darkmatter5 Posted July 24, 2008 Share Posted July 24, 2008 I need to have a dropdown list and a submit button that when a selection is made in the list and the submit button is clicked the current page is reloaded with the value of the selection of the list. Something like this: <form method="post"> <select name='pet' tabindex='2'> <option>---Select---</option> <option value='1'>dog</option> <option value='2'>cat</option> </select> <input name='load' type='submit' onclick="editpet.php?pet=$_POST["pet"]" value='Load record' /> </form> The reason for all this is I want when the page is reloaded to then display with the selection from the list selected in the list. So if I can get the value to pass on the reload I have then write code to have that selection be selected in the list. Any thoughts? Any suggestions? Link to comment https://forums.phpfreaks.com/topic/116451-list-selection-and-pass-value-as-varibale-in-url/ Share on other sites More sharing options...
MFHJoe Posted July 24, 2008 Share Posted July 24, 2008 <?php // If the form has been submitted... if(isset($_POST['load'])) { // Set $name as the value of the name field in your form ($_POST just references the form) $pet = $_POST['pet']; echo $pet; } // If the form hasn't been submitted yet... else { // Display the form echo '<form method="post"> <select name="pet" tabindex="2"> <option>---Select---</option> <option value="1">dog</option> <option value="2">cat</option> </select> <input name="load" type="submit" value="Load record" /> </form>'; } ?> Should do the trick. Let me know if you need any more help with how that code works. Link to comment https://forums.phpfreaks.com/topic/116451-list-selection-and-pass-value-as-varibale-in-url/#findComment-598830 Share on other sites More sharing options...
Darkmatter5 Posted July 24, 2008 Author Share Posted July 24, 2008 Thanks, got it working great! Link to comment https://forums.phpfreaks.com/topic/116451-list-selection-and-pass-value-as-varibale-in-url/#findComment-598898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.