ryanmetzler3 Posted September 4, 2013 Share Posted September 4, 2013 I have not been able to find this on YouTube or the internet surprisingly. Anyways I got a simple select form here. I was not real sure where to put "name" and "value" tags. Anyways here it is: <html> <head> </head> <body> Select Your School: <form method="post"> <select> <option value="LCCC">Lorain County Community College</option> <option value="CSU">Cleveland State University</option> <input type="submit" value="Submit" /> </select> </form> </body> </html> How can I use PHP to parse to a new page based on their selection? For example if they choose LCCC then it will go to "lccc.php" or if they choose CSU it will go to "csu.php"? Quote Link to comment Share on other sites More sharing options...
trq Posted September 4, 2013 Share Posted September 4, 2013 You wouldn't use php for that. Its a client side issue, use Javascript. <html> <head> <script src="http://codeorigin.jquery.com/jquery-1.10.2.min.js"></script> <script> $(document).ready( function() { $('#select').change( function() { location.href = $(this).val(); }); }); </script> </head> <body> Select Your School: <form method="post"> <select> <option value="lccc.php">Lorain County Community College</option> <option value="csu.php">Cleveland State University</option> </select> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted September 4, 2013 Share Posted September 4, 2013 As trq suggested, you could use JavaScript/jQuery to direct visitors to the proper page. Just keep in mind that JavaScript can be disabled. Since this seems like a critical interaction, it's a good idea to have a backup. To redirect visitors using PHP, you would need to name the <select> element. That lets you access the selection in PHP. You can then redirect the visitor to the proper page using the header() function. http://php.net/manual/en/function.header.php With that said, can the pages for LCCC and CSU be merged? If they are similar enough, perhaps you could use the form selection to populate one page based on a database? Quote Link to comment 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.