omega1983 Posted January 8, 2014 Share Posted January 8, 2014 I have an html form that allows user to enter data. Data type for the most part is text. I want to have a drop down to allow people to choose and have it populate a database. In the database I have golfer_1 golfer_2 golfer_3 How can I create the drop down so that php will populate base on the choice made by customer and have it populate the database. I am ok with the populating based on text Link to comment https://forums.phpfreaks.com/topic/285216-php-page-to-populate-database/ Share on other sites More sharing options...
ginerjm Posted January 8, 2014 Share Posted January 8, 2014 Thought I knew what you wanted til I read this: populate base on the choice made Huh? Link to comment https://forums.phpfreaks.com/topic/285216-php-page-to-populate-database/#findComment-1464502 Share on other sites More sharing options...
dungpt29 Posted January 9, 2014 Share Posted January 9, 2014 Something like this: <form id="frmGolfer" name="frmGolfer" action="" method="post"> <select id="seGolfer" name="seGolfer" size="1"> <option value="golfer_1">Golfer 1</option> <option value="golfer_2">Golfer 2</option> <option value="golfer_3">Golfer 3</option> </select> </form> $(document).ready(function(){ $("#seGolfer").change(function(){ document.getElementById("frmGolfer").submit(); }); }); In your PHP page, switch...case syntax should be used to process the case of which golfer being selected, as follows: <?php $golfer = $_POST["seGolfer"]; switch ($golfer) { case 'golfer_1': // Code to process the case of golfer_1 being selected break; case 'golfer_2': // Code to process the case of golfer_2 being selected break; case 'golfer_3': // Code to process the case of golfer_3 being selected break; } ?> Link to comment https://forums.phpfreaks.com/topic/285216-php-page-to-populate-database/#findComment-1464558 Share on other sites More sharing options...
dungpt29 Posted January 9, 2014 Share Posted January 9, 2014 <script type="text/javascript" language="javascript"> //<![CDATA[ $(document).ready(function(){ $("#seGolfer").change(function(){ document.getElementById("frmGolfer").submit(); }); }); //]]> </script> I am sorry for forgetting putting JavaScript code in script tags Link to comment https://forums.phpfreaks.com/topic/285216-php-page-to-populate-database/#findComment-1464597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.