I tired of solving this problem but believe I'm missing something.

I'm not receiving values from request.getParameterValues of "mmsTitleAdded"

Here is the process I'm using:


This <tr> contains the MMSCategory list and onChange a javascript function is called which gets the the list of all the mmsTitles of that category:

Code for <tr> of MMSCategory & mmsTitles:

<tr class=blackbold>
	<td class=TextFont>MMS Category</td>
	<td class=TextFont>
		<select name="MMSCategory" id="MMSCategory" style="width:148" onchange="javascript:fetchCannedMessaged(this.value);">
			<%
				%>
					<option value="Select MMS Category">Select MMS Category</option>
				<%
				for(int i=0;i<mms_category.size();i++){
					%>
						<option value="<%=mms_id.get(i) %>"><%=mms_category.get(i) %></option>							
					<%
				}
			%>
		</select>
	</td>
</tr>
<tr class=blackbold>
	<td class=TextFont>MMS Title</td>
	<td class=TextFont>
	<div id="render">
		<select multiple="multiple" size=5 name="mmsTitle" id="mmsTitle" style="width:148" onchange="javascript:alert();">
			<option value="Select MMS Title">Select MMS Title</option>
		</select>
	</div>
	</td>
</tr>

This is JavaScript/AJAX function is called on onChange of a select list and gets the list of mmsTitles for the selected category.

function fetchCannedMessaged(val){
	if(val == 'Select MMS Category'){
		return;
	}else{
		document.getElementById('selected_MMSCategory').value = val;
		alert("document.getElementById('selected_MMSCategory').value "+document.getElementById('selected_MMSCategory').value );
		var xhttp;
		if (window.XMLHttpRequest){
			xhttp=new XMLHttpRequest();
		}
		else{
			xhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xhttp.onreadystatechange = function(){
			if((xhttp.readyState == 4) && (xhttp.status == 200)){
				var resp = xhttp.responseText;
				alert(resp);
				document.getElementById('render').innerHTML=resp;
				
				
			}else{
			}
		}
		var url = "Process_CannedMessages.jsp?mms_id="+val;
		xhttp.open("POST",url,false);
		xhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xhttp.send(null);
	}
}

Here is the relevant code of Process_CannedMessages.jsp which is called above in the AJAX function:

<%
Connection connlocal = null;
connlocal = DBUtils.getConnection("default");
System.out.println("->getPARAMETER: "+request.getParameter("mms_id"));
String mms_id = request.getParameter("mms_id");
String query = "select canned_id,title from proxy_canned_details where mms_categoryid='"+mms_id+"' ORDER BY canned_id DESC;";
Vector results = null;
String render ="";
render =	"<table> <tr> <td> <select multiple='multiple' size=8 name='mmsTitle' id='mmsTitle' style='width:148' onchange=''>";
results = DBUtils.getVectorResult(connlocal,query);
String[]arr = new String[results.size()];
for(int i=0;i<results.size();i++){
	arr = (String[])results.get(i);
	render	=	render + "<option value='"+arr[0]+"'>"+arr[1]+"</option>";
}

render = render + "</select></td>";

render = render +"<td align ='top'><input type='button' value='<<' onClick='javascript:moveOptions(this.form.mmsTitleAdded,this.form.mmsTitle);'/>"
				+"<input type='button' value='>>' onClick='javascript:moveOptions(this.form.mmsTitle, this.form.mmsTitleAdded);'/><NOBR></td>"
				+"<td><select multiple='multiple' size=8 name='mmsTitleAdded' id='mmsTitleAdded' style='width:148'>"
				+"</select></td> </tr> </table>";

String resp = ""+arr[0]+","+arr[1]+"";
	System.out.println("resp:"+resp);
	out.println(render);
%>

And Finally, (thank you for bearing this far)

I am submitting the form in which <tr> are defined (First Code above) whose action"Submit_package_details.jsp"

Here is the Code for Submit_package_details.jsp:

String pack_name 		= request.getParameter("selected_pack_name");
String mmsCategory		= request.getParameter("selected_MMSCategory");
String scheduled_date 	= request.getParameter("scheduled_date");
String[]mmsTitleAdded 	= request.getParameterValues("mmsTitleAdded");   // PROBLEM AREA: NOT GETTING VALUE HERE

System.out.println(pack_name);			// GETTING VALUE
System.out.println(mmsCategory);		// GETTING VALUE
System.out.println(scheduled_date);		// GETTING VALUE


	for(int i=0;i<mmsTitleAdded.length;i++){
		System.out.print(mmsTitleAdded[i]+" ");		//NOT GETTING VALUE 
	}

NOT GETTING VALUES IN ABOVE CODE IN

String[]mmsTitleAdded = request.getParameterValues("mmsTitleAdded");

SINCERE THANK YOU FOR READING THIS FAR.

I don't see any form element with the name "mmsTitleAdded" which kind of explains why you are not getting any values (unless you have not posted the code which shows this element). If you are trying to get the multiple values of the "SELECT" in your first code snippet, try using "mmsTitle" instead. Also, you can always view what kind of data is submitted to the server using a tool like Firebug extension for Firefox. Really handy I must say to see *what* gets submitted to your server.

Oh and BTW, your code is *really* messy. Avoid using scriptlets in your JSP markup and make sure your internal Ajax requests return a JSON object instead of a "HTML fragment". Sure, the way you have done it makes it easier but unless it's a short term project (school project), maintaining this complicated piece of code would become more and more difficult as the code base grows.

I don't see any form element with the name "mmsTitleAdded" which kind of explains why you are not getting any values (unless you have not posted the code which shows this element). If you are trying to get the multiple values of the "SELECT" in your first code snippet, try using "mmsTitle" instead. Also, you can always view what kind of data is submitted to the server using a tool like Firebug extension for Firefox. Really handy I must say to see *what* gets submitted to your server.

Oh and BTW, your code is *really* messy. Avoid using scriptlets in your JSP markup and make sure your internal Ajax requests return a JSON object instead of a "HTML fragment". Sure, the way you have done it makes it easier but unless it's a short term project (school project), maintaining this complicated piece of code would become more and more difficult as the code base grows.

There is mmsTitleAdded in the 3rd code box.
I'm rendering it using AJAX.
Though thank you for suggesting code improvements.

OK, my bad, must have missed that. Anyways, did you try inspecting the HTTP request sent to your servlet using Firebug as suggested previously?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.