View Full Version : Dropdown From XML

05-26-2009, 08:36 AM
I have a drop down field that is dynamically populated using an XML sheet that looks like:

<category link="0">
<category link="1">
<title>Bagua 3 April</title>
<category link="2">
<title>Anthony Practice</title>

I populate the dropdown box using javascript that looks like this:

<script type="text/javascript">
type: "GET",
url: "galleries.xml",
dataType: "xml",
success: function(xml) {
var select = $('#mySelect');
var title = $(this).find('title').text();
select.children(":first").text("please make a selection").attr("selected",true);

My the drop down form looks like this:

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

When a user clicks on the drop down box, all of the values inside "<title>" tags get displayed. Once the user has made their selection, the form is submitted and posts the user's option. My problem is that when the user clicks on the drop down box, I want them to see the content included in the "<title>" text but I want the form to post the data included in the "<xml>" tags.

For example, if the user clicks on the drop down menu and selects the option 'Animals' I want the form to post 'xml/animals.xml'. Any ideas how to handle this?

05-27-2009, 04:46 AM
Hey I finally got this working. For anyone who gets a similar problem, here is what my fix looked like:


var title = $(this).find('title').text();
var val = $(this).find('xml').text();
select.append("<option value='"+val+"'>"+title+"</option>");

Reply With Quote Quick reply to this message