PDA

View Full Version : How to Display a user's last selection in drop down



rmagnes
05-27-2009, 06:10 AM
I am working on a drop down box that loads its options dynamically from an xml file. The XML file has two nodes for each option: the title node is what gets displayed in the drop down and the 'xml' node which contains the data that actually gets submitted. When a user submits the form, the action is processed by the php in the top of the page. Essentially, submitted data is turned in to a session variable at the top of the page. I need to figure out how to display the user's last choice in the dropdown menu. Since the data submitted is not the same as the data displayed, I can't figure out a way to show this... Any suggestions?



<?php
session_start(); // start up your PHP session!
$_SESSION['views'] = $_POST['selectBox'];
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Sample</title>

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "galleries.xml",
dataType: "xml",
success: function(xml) {
var select = $('#mySelect');
$(xml).find('category').each(function(){
var title = $(this).find('title').text();
var val = $(this).find('xml').text();
select.append("<option value='"+val+"'>"+title+"</option>");
});
select.children(":first").text("please make a selection").attr("selected",true);
}
});
});
</script>

</head>
<body>
<form name="myform" action="index.php" method="post" enctype="multipart/form-data">
<select name="selectBox" id="mySelect" onChange="document.myform.submit()">
<option>loading</option>
</select>
</form>

</body>
</html>