Link to home
Start Free TrialLog in
Avatar of gazdzid
gazdzidFlag 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!!
Avatar of amitkathpal123
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

Avatar of 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
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

Avatar of 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
Avatar of amitkathpal123
amitkathpal123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gazdzid

ASKER

I would like to check the suggestion provided.  If possible please be patient and I will reply or award points.
Avatar of gazdzid

ASKER

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

ASKER

will look at response