AKholic Posted June 13, 2012 Share Posted June 13, 2012 Hi, I am trying to get page content to load based on a selection made from a drop down list. I have been trying to modify the code below to work for me but with no luck. I need the Page1 and Page2 values to appear in a drop down menu and the page content to load (below the form) when a value is selected. Anyone have an idea of how I could accomplish this, I don’t know that much about PHP so it’s probably something simple.. Any help is appreciated. Thanks!! <?php echo '<a href="index.php?page=1">Page 1</a> | <a href="index.php?page=2">Page 2</a><br><br>'; if ($_GET['page']=="1"){ include("Content/page1.php"); }elseif ($_GET['page']=="2"){ include("Content/page2.php"); }else{ include("Content/home.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/264116-load-content-based-on-selection/ Share on other sites More sharing options...
insidus Posted June 13, 2012 Share Posted June 13, 2012 This would be done with using AJAX.. HTML Form <div> <select id="select"> <option value="1">Hello</option> <option value="1">Goodbye</option> </select> </div> <div id="ajax"> </div> jQuery $(document).ready(function() { $("#select").change(function(){ var d = $("#select:option selected").text(); //.var .html <- can't remember which function alert(d) // make sure you got the right value $.ajax({ type: "POST", url: ajax.php, data: "load=" + d, success: function(html){ $("#ajax").html(html); // where to out the data }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("Error jQuery - Ajax - 1"); } }); }); }); ajax.php <?php $select = $_POST['load']; // do stuff here echo $select // this goes into the #ajax div in index.php Quote Link to comment https://forums.phpfreaks.com/topic/264116-load-content-based-on-selection/#findComment-1353509 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.