Forum Moderators: open
Here is javascript function that handles this:
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>
I am fairly new to JS and AJAX, please give me some hints or suggestions,
Thanks in advance