Hi guys,
i am new to JSP that is why i look forward your assistance. I have a JSP page where 3 drop down lists are.
on the basis of selected value from first drop down i need to have trigg new values into 2nd drop down and similarly in 3rd i have to have on the basis of 2nd...
Data: i have retrieved one arraylist of objects from database (through Servlet) where first object contains set of second type of objects and second type of object has a set of 3rd type of objects. e.g. Object1.getObject2s().getObject3s()
what i have in arraylist is just firstkind of object through servlet in jsp page. but i am unable to retrieve it for filter second type of drop down box. even though i have data in the arraylist.
I just used following example but it is not fruitful...example is
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<script language="javascript" type="text/javascript">
// And in the list.js file
function fillCategory()
{
// this function is used to fill the category list on load
addOption(document.drop_list.Category, "Fruits", "Fruits", "");
addOption(document.drop_list.Category, "Games", "Games", "");
addOption(document.drop_list.Category, "Scripts", "Scripts", "");
}
function SelectSubCat()
{
// ON selection of category this function will work
removeAllOptions(document.drop_list.SubCat);
addOption(document.drop_list.SubCat, "", "SubCat", "");
if(document.drop_list.Category.value == 'Fruits')
{
addOption(document.drop_list.SubCat, "Mango", "Mango");
addOption(document.drop_list.SubCat, "Banana", "Banana");
addOption(document.drop_list.SubCat, "Orange", "Orange");
}
if(document.drop_list.Category.value == 'Games')
{
addOption(document.drop_list.SubCat, "Cricket", "Cricket");
addOption(document.drop_list.SubCat, "Football", "Football");
addOption(document.drop_list.SubCat, "Polo", "Polo", "");
}
if(document.drop_list.Category.value == 'Scripts')
{
addOption(document.drop_list.SubCat, "PHP", "PHP");
addOption(document.drop_list.SubCat, "ASP", "ASP");
addOption(document.drop_list.SubCat, "Perl", "Perl");
}
if(document.drop_list.Category.value == 'Fruits')
{
addOption(document.drop_list.SubCat, "Mango", "Mango");
addOption(document.drop_list.SubCat, "Banana", "Banana");
addOption(document.drop_list.SubCat, "Orange", "Orange");
}
}
function SelectSub2Cat()
{
// ON selection of category this function will work
removeAllOptions(document.drop_list.Sub2Cat);
addOption(document.drop_list.Sub2Cat, "", "Sub2Cat", "");
if(document.drop_list.SubCat.value == 'Mango')
{
addOption(document.drop_list.Sub2Cat, "Mango1", "Mango1");
addOption(document.drop_list.Sub2Cat, "Banana1", "Banana1");
addOption(document.drop_list.Sub2Cat, "Orange1", "Orange1");
}
if(document.drop_list.SubCat.value == 'Cricket')
{
addOption(document.drop_list.Sub2Cat, "Cricket1", "Cricket1");
addOption(document.drop_list.Sub2Cat, "Football", "Football");
addOption(document.drop_list.Sub2Cat, "Polo1", "Polo1", "");
}
if(document.drop_list.SubCat.value == 'PHP')
{
addOption(document.drop_list.Sub2Cat, "PHP1", "PHP1");
addOption(document.drop_list.Sub2Cat, "ASP1", "ASP1");
addOption(document.drop_list.Sub2Cat, "Perl1", "Perl1");
}
}
/////////////////////////
function removeAllOptions(selectbox)
{
var i;
for(i = selectbox.options.length - 1; i >= 0; i -- )
{
// selectbox.options.remove(i);
selectbox.remove(i);
}
}
function addOption(selectbox, value, text )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
</script>
<title>(Type a title for your page here)</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onload="fillCategory();">
<FORM name="drop_list" action="a.html" method="POST" >
<SELECT NAME="Category" onChange="javascript:SelectSubCat();" >
<Option value="">Category</option>
</SELECT>
<SELECT NAME="SubCat" onChange="javascript:SelectSub2Cat();">
<Option value="">SubCat</option>
</SELECT>
<SELECT NAME="Sub2Cat">
<Option value="">Sub2Cat</option>
</SELECT>
</FORM>
</body>
</html>
it would be great if you reply me as soon as possible.
Thanks in advance.
Romi