Connected Combo box problem !please help me

Dear Friends....!

I am developing project in which i have 3 combo :

1) District Selection

2) Taluka Selection

3) Village Selection

Depend on village selection , perticular persons on that village is displayed on the page.

This values must be fetched from DATABASE !

<b> I tried with JAVASCRIPT but with it i can connect two combo and

can't access database inside javascript.WHAT IS THE SOLUTION EXCEPT AJAX ( That i don't KNOW ) </b>

may be i can put 3 combo together and on first OnChange event

i can submit page and process another page and put values in

another combo and forward page to combo page again.

i am very much confused HELP ME !

please i don't know AJAX else problem would be easily solved.

EVEN I CAN"T MANUALLY PUT DATA IN JAVASCRIPT bcoz my villages

are more than 400.

how to put java database code in javascript OnChange event ?

to fetch data of another combo ?

HELP WITH EASY SOLUTION.

Thanks

GHanshyam

================================

SOLUTION FOR TWO COMBO

function populate(o){

d=document.getElementById('de');

if(!d){return;}

var mitems=new Array();

mitems['Choose']=[''];

mitems['Salads']=['Select Item','Tuna Salad','Cesar Salad','Green Salad','Prawn Salad'];

mitems['Main Courses']=['Select Item','Filet Mignon','Porterhouse','Flank','T-Bone'];

mitems['Drinks']=['Select Item','Milkshake','Soda','Mixed Drink','Juice'];

mitems['Desserts']=['Select Item','Ice Cream','Fresh Fruit','Pie'];

mitems['Snacks']=['Select Item','Brownies','Cookies','Potato Chips'];

d.options.length=0;

cur=mitems[o.options[o.selectedIndex].value];

if(!cur){return;}

d.options.length=cur.length;

for(var i=0;i<cur.length;i++){

d.options[i].text=cur[i];

d.options[i].value=cur[i];

}

}

><!-- Pastethis code into the HEAD section of your HTML document.

You may need to change the path of the file. -->

<script type="text/javascript" src="dropdownBox.js"></script>

<!-- Pastethis code into the BODY section of your HTML document -->

<form action="" method="get">

<label for="or">Our menu:</label>

<select name="or" id="or" onchange="populate(this)">

<option value="Choose">Select from the Menu</option>

<option value="Salads">Salads</option>

<option value="Main Courses">Main Courses</option>

<option value="Drinks">Drinks</option>

<option value="Deserts">Deserts</option>

<option value="Snacks">Snacks</option>

</select>

<label for="de">Select:</label>

<select name="de" id="de"></select>

<input type="submit" value="Show me" />

</form>

<div align="center">

</div>

[4932 byte] By [Ghanshyama] at [2007-11-27 6:40:18]
# 1

> may be i can put 3 combo together and on first

> OnChange event

> i can submit page and process another page and put

> values in

> another combo and forward page to combo page again.

Almost there. What you should do is submit the page on the onChange event of the combo box; but submit to the same JSP. Then, depending on the values that each of the combo boxes contains, run a query for villages in that District and under that Talluka.

And populate the third combo box. If any one of the ( first two ) boxes is empty i.e user didnt' select a value, then you'll automatically get no value for the combo boxes from the query.

Something like this

<%

String selectedDistrict = request.getParameter("districtcombobox");

String selectedTalluka = request.getParameter("tallukacombobox");

//make sure you don't nulls

selectedDistrict = selectedDistrict == null?"":selectedDistrict;

selectedTalluka = selectedTalluka == null?"":selectedTalluka;

PreparedStatement psFetchTallukas = con.prepareStatement("select tallukaname from tallukas where tallukadistrict = ?");

PreparedStatement psFetchVillages = con.prepareStatement("select villagename from villages where villagetaluka = ?");

psFetchTallukas.setString(1, selectedDistrict);

psFetchVillages.setString(1, selectedTalluka);

rsTallukas = psFetchTallukas.executeQuery();

rsVillages = psFetchVillages.executeQuery();

//now, print out your <option> elements under the corresponding <select> tags for each of the 3 select boxes

%>

For your onChange event you don't need to do anything except call form.submit() where the action should be the same JSP. In case your form is going to be submitted to another page on the final submit i.e after selecting all required values; then in the onChange event handler, before the submit(), you should change the action property of the form to the same page and then submit.

nogoodatcodinga at 2007-7-12 18:09:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for your openioni will try and it will sure help me to achieve this.Again thanksIf any query hope u will solve regarding this project.b in touch.
Ghanshyama at 2007-7-12 18:09:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...