/    Sign up×
Community /Pin to ProfileBookmark

Problem with third dynamic select box being replaced

hi experts, In my app, I have multi-level dependent select boxes using AJAX retrieving data from database.

RIght now I can get second select box hide/show depending on the selection from first select box. But I am having trouble to get third select box to hide when different selection is made from second box. right now it doesn’t replace the old box with new one, it keeps appending to it. I’ve tried many ways to solve the problem, but no luck on me yet.

Here is javascript function that handles this:

[code]
function getSecond(Pid) {
var ParentCat = $(Pid); //obj of parent selection
var url = ‘http://kewei-desktop:3000/admin/subcategories/category/’ + ParentCat.value;
var divIdName = “category_”+ParentCat.value+”_children”;

new Ajax.Request( url,
{
method: ‘post’,
onSuccess: function(transport) {
var response = transport.responseText;
var tmp = document.createElement(“div”);
tmp.setAttribute(“class”, “SubCategory”);
tmp.setAttribute(“id”, divIdName);
// response returns HTML text of the whole select box,
// when there is no child, response.length is 4.
if ( response.length > 4 ) {
$(“linkInfo”).removeChild($(“linkInfo”).lastChild);
$(“linkInfo”).appendChild(tmp);

}
else {
$(“linkInfo”).removeChild($(“linkInfo”).lastChild);
$(“linkInfo”).appendChild(tmp);
}
}
}
)
}
</script>
[/code]

I am fairly new to JS and AJAX, please give me some hints or suggestions,
Thanks in advance

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManAug 17.2007 — sorry, when you use libraries like protocol.js and whatever else, you should post these questions to their support forums. people here are generally javascript adept, not third party library X adept.
Copy linkTweet thisAlerts:
@jj0914authorAug 17.2007 — there were people asking the questions related to JS, I am just trying my luck.

if you can't answer it, that's fine. you don't need to reply
Copy linkTweet thisAlerts:
@Angry_Black_ManAug 17.2007 — im not saying you cant post, im saying thats why it had 0 replies and trying to give you a way to actually get some solutions. if i hadnt posted, you wouldnt know that you'd have better luck on the actual library's forum. thats helping!

but the lack of replies will prove itself.
Copy linkTweet thisAlerts:
@jj0914authorAug 17.2007 — sorry, aaron, i misunderstood you. I am new to JS and prototype.js, if you know any good forums that can help me on my problem, I will appreciate.
×

Success!

Help @jj0914 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.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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