Avatar of gazdzid
gazdzid
Flag for United States of America asked on

Request for Ajax - Double Combo Box in JAVA

Hello,

I was hoping that someone could provide me with an Ajax example for a double combo dropdown box that is in JAVA/jsp.  I seem to find examples written in asp but Ibut have difficulties finding java/jsp. The example that I am looking for would accomplish the following:

Based on a selection within a dropdown field, a second select field will be populated.

Please provide an example that has the html code, javascript code, and the java or jsp code.

Thanks in advance for your assistance!!
JavaScriptJSPAJAX

Avatar of undefined
Last Comment
gazdzid

8/22/2022 - Mon
amitkathpal123

The given code might help.
In this code, on change of value in first drop down, it automatically changes value in the second drop down.
<html>
<head>
<script type="text/javascript">
function changeValuesInSecondDropDown() {
	var dropDown1 = document.getElementById('dropDown1');
	var dropDowm2 = document.getElementById('dropDown2');
	dropDowm2.selectedIndex=dropDown1.selectedIndex;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form>
<select name="dropDown1" onchange="changeValuesInSecondDropDown()">
	<option>Select Something</option>
	<option>Select1</option>
	<option>Select2</option>
	<option>Select3</option>
</select>
 
<BR><BR>
<select name="dropDown2">
	<option></option>
	<option>1 Selected</option>
	<option>2 Selected</option>
	<option>3 Selected</option>
</select>
</form>
</body>
</html>

Open in new window

amitkathpal123

gazdzid

ASKER
amitkathpal123:and amitkathpal123:,

Let me clarify, it is a dynamic dropdown,  my thought is I should be able to pass in a field value and NEXT dropdown name.  The server would return values the values for the NEXT dropdown.

I found something that I thought was close however it is written in asp, which can be found below but I would like the third page (within link) to be jsp.

http://www.developer.com/services/article.php/10928_3575081_1/Creating-a-Double-Combo-Linked-List-with-Ajax.htm
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
amitkathpal123

Check the given code and go through above link for java method:
http://www.hiteshagrawal.com/ajax/ajax-programming-with-jsp-and-servlets
<script>
 
    function populateValuesInSecondDropDown() {
	var obj = document.getElementById('dropDownList1');
	var val = obj.options[obj.selectedIndex].value;
 
	// Ajax Call Here. Java Class method to be called for getting  //    response 'getListForDropDown'
	// and 'showDropDownList' is the javascript call back method // which will be called automatically after response came back  
	
	var req = AJAXHttpRequest();
	req.onreadystatechange = getReadyStateHandler(req, showDropDownList);
	var timeStamp = new Date();
	var url = 'getListForDropDown?param='+val;
	req.open("get", url, true);
	req.send(null);
}
 
function showDropDownList(response) {
	// Display here all values(value will be in response) in drop //down
}
 
</script>
 
<select name="dropDownList1" onchange="populateValuesInSecondDropDown()">
        <option>Select Something</option>
        <option>op1</option>
        <option>op2</option>
        <option>op3</option>
</select>

Open in new window

gazdzid

ASKER
You wrote

// Ajax Call Here. Java Class method to be called for getting  //    response 'getListForDropDown'
      // and 'showDropDownList' is the javascript call back method // which will be called automatically after response came back  

Can you tell me the sever code if you look at page 3 it is in asp. I am looking for the jsp equivelant.
      
ASKER CERTIFIED SOLUTION
amitkathpal123

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gazdzid

ASKER
I would like to check the suggestion provided.  If possible please be patient and I will reply or award points.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
gazdzid

ASKER
I wiil look at responce, sorry for the delay.
gazdzid

ASKER
will look at response
gazdzid

ASKER
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes