Results 1 to 2 of 2

Thread: Dropdown From XML

  1. #1
    Join Date
    Aug 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dropdown From XML

    I have a drop down field that is dynamically populated using an XML sheet that looks like:

    Code:
    <content>
    	<category link="0">
    		<title>Animals</title>
    		<xml>xml/animals.xml</xml>
    	</category>
    	<category link="1">
    		<title>Bagua 3 April</title>
    		<xml>xml/bagua.xml</xml>
    	</category>
    	<category link="2">
    		<title>Anthony Practice</title>
    		<xml>xml/Anthony.xml</xml>
    	</category>
    </content>
    I populate the dropdown box using javascript that looks like this:
    Code:
    <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();
    						select.append("<option>"+title+"</option>");
    					});
    					select.children(":first").text("please make a selection").attr("selected",true);
    				}
    			});
    		});
    </script>
    My the drop down form looks like this:
    Code:
    		<form name="myform" action="dropdown.php" method="post" enctype="multipart/form-data">
               <select name="selectBox" id="mySelect" onChange="document.myform.submit()">
                  <option>loading</option>
               </select>
           </form>

    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?

  2. #2
    Join Date
    Aug 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey I finally got this working. For anyone who gets a similar problem, here is what my fix looked like:

    [CODE]

    $(xml).find('category').each(function(){
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •