Get The Selected Option Of Select & Show The Selected Option In Php February 28, 2024 Post a Comment I have tried a lot & searched a lot but i didn't found the solution. I have HTML code HTML Solution 1: <formid="program_mode"action=""method="post"><selectname="mode"id="mode"onchange="val_changed()"><option>Select</option><optionvalue="<?phpecho$vars['url']?>pg/event_calendar/all"<?phpif($mode == 'All') echo'selected="selected"'; ?>>All</option><optionvalue="<?phpecho$vars['url']?>pg/event_calendar/anytime"<?phpif($mode == 'Online') echo'selected="selected"'; ?>>Online</option><optionvalue="<?phpecho$vars['url']?>pg/event_calendar/offline"<?phpif($mode == 'Offline') echo'selected="selected"'; ?>>Offline</option></select></form>CopyWith little jquery you can do with this<script>functionval_changed() { var mode=$('#mode').val(); } </script>CopySolution 2: Ya sure, if you want to submit the form you can use form.submit() in onchange event of the dropdown like:<select name="mode"id="mode" onchange="form.submit();"> CopyAnd can access the value in PHP like:if(isset($_POST['mode'])){ var_dump($_POST['mode']); //extra code } CopyIf you dont want to submit the form you can just use a jquery function to pick the selected value: Then remove the onchange event handler from select box as:<select name="mode"id="mode"> Copyand just add the following jquery function:$('#mode').change(function(e) { var val = $(this).val(); alert(val); }); CopySolution 3: If you want PHP to get the value only when the option is change, you should use JavaScript or jQuery. Include the jQuery library :<scriptsrc="http://code.jquery.com/jquery-latest.js"></script>CopyThen add the following code in a <script></script> tag.$(document).ready(function(){ $("#mode").change(function(){ $.post("php_file.php", {mode:$(this).val()}); }); }); CopyWhen the option changes, jQuery will send a POST request in the background to the php_file.php with mode value. PHP will take care of the rest.This works normally like a form submitted to the PHP file. So you will get the $_POST['mode'] value in the PHP file. Share Post a Comment for "Get The Selected Option Of Select & Show The Selected Option In Php" Top Question Right Floated Element Disappears When Using Columns In Firefox I am using an ol element with column-count and column-gap p… How To Resize Parent By Dragging One Of It's Children? Essentially i want to resize the green box by dragging the … How Do I Pass A Value In A Input Box, To Another Input Box I am trying to pass values between boxes. So, When a User … How Does An OS Pick Up The Correct Ico/favicon Size? Based on this stackoverflow discussion, one can provide var… How To Find Absolute Or Relative Position Of Text Or In HTML? I was wondering if there is a way I could find the position… JQuery Show Submenu If Parent Have Been Clicked Could some one please help with code. I want to show the su… What Is The Correct Way For Redirecting From The Domain Name Itself To A Page In A Directory? I want anyone browsing for 'MyDomain.com' to see wh… Html Formatted Text In An Email In Java try{ String msg='Happy BirthDay Dear, '+na… Material Design Icon Isn't Working On Ie 11 I'm using MaterialDesign icons on my application, howev… R: Output A Pivot-like Table With Subtotals I'm trying to make a cross tabulation in R, and having … December 2024 (1) November 2024 (37) October 2024 (58) September 2024 (17) August 2024 (370) July 2024 (337) June 2024 (695) May 2024 (1294) April 2024 (826) March 2024 (1551) February 2024 (1690) January 2024 (1348) December 2023 (1319) November 2023 (287) October 2023 (569) September 2023 (333) August 2023 (342) July 2023 (279) June 2023 (379) May 2023 (202) April 2023 (144) March 2023 (133) February 2023 (166) January 2023 (257) December 2022 (139) November 2022 (205) October 2022 (175) September 2022 (157) August 2022 (295) July 2022 (96) Menu Halaman Statis Beranda © 2022 - Html5 News