Jump to content

Load content based on selection


AKholic

Recommended Posts

:confused:

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");

}

 

?>

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.