/    Sign up×
Community /Pin to ProfileBookmark

Java Dropdown and 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>
[/CODE]

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>
[/CODE]

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>
[/CODE]

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?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@fangonkauthorMay 27.2009 — 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

[/CODE]
×

Success!

Help @fangonk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...