Problem in dropdown with db

<script>

function filldroplist1(){

// this function is used to fill the droplist1 list on load

addOption(document.formname.droplist1,"1","Glazing","");

addOption(document.formname.droplist1,"2","Cladding","");

addOption(document.formname.droplist1,"3","Louver","");

}

function Selectdroplist2(){

// ON selection of droplist1 this function will work

removeAllOptions(document.formname.droplist2);

addOption(document.formname.droplist2,"","droplist2","");

document.formname.action="samepage.jsp?value1="+document.formname.droplist1.value;

document.formname.submit();

document.write(value1)

<%

String prod = (String)request.getParameter("value1") !=null ? (String)request.getParameter("value1") :"none";

out.println("droplist1" +prod);%>

if(document.formname.droplist1.value !='none'){

<%//here getting values from database %>

//adding with drop down here

addOption(document.formname.droplist2,"","<%= product_sub%>");

} %>}}

Here while choosing drop list1 it gets datas from db to drop list2..

My problem is , i can get the values from db but not able to add it to the drop list2?

Could anybody tell me?What is wrong with it?

Suggestions greatly appreciated..

[2259 byte] By [a1ba] at [2007-11-27 5:06:06]
# 1

You seem to mixing up JavaScript and JSP. JavaScript runs on the client-side after the JSP code has run on the server-side and created your page.

So on the change event of dropdown1 you should submit the page; you don't even need to change the action of the form, you can retrieve the value chosen with request.getParameter().

After that you should generate the HTML page with dropdown2 populated with relevant items.

nogoodatcodinga at 2007-7-12 10:24:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
As per given code, it looks like syntax issue. check braces...
skp71a at 2007-7-12 10:24:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

function SelectProduct_sub1(){

// ON selection of category this function will work

removeAllOptions(document.drop_list.Product_sub1);

addOption(document.drop_list.Product_sub1, "", "Product_sub1", "");

var value1 = document.getElementById("drop_list").Category.selectedIndex;

document.write(value1)

document.drop_list.submit();

<%

String prod = (String)request.getParameter("value1") != null ? (String)request.getParameter("value1") : "none";

out.println("Category" +prod);%>

Thanks, Without action it simply displays the value(say 1 )..No drop lists.

I checked the syntaxes too..

a1ba at 2007-7-12 10:24:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Sorry small correction in the above code..

function Selectdroplist2(){

// ON selection of droplist1 this function will work

removeAllOptions(document.formname.droplist2);

addOption(document.formname.droplist2, "", "droplist2", "");

var value1 = document.getElementById("formname").droplist1.selectedIndex;

document.formname.submit();

document.write(value1)

<%

String prod = (String)request.getParameter("value1") != null ? (String)request.getParameter("value1") : "none";

out.println("droplist1" +prod);%>

When i select the first option it simply displays 1..No drop lists .

a1ba at 2007-7-12 10:24:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...