Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not receiving values in request.getParameterValues.

    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:
    Code:
    <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.

    Code:
    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:
    Code:
    <%
    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:
    Code:
    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.

  • #2
    Regular Coder
    Join Date
    Jan 2009
    Location
    india
    Posts
    145
    Thanks
    0
    Thanked 5 Times in 5 Posts
    I can't find a form with action Submit_package_details.jsp, where's it ?
    Again, honestly, this code is horrible, follow certain best practices, No scriptlet's if possible, otherwise keep it minimum, No database calls from JSP, instead of using bare XMLHttpRequest you are better at using some library like jquery.

    I just can't find the relevant code from what you have posted, otherwise getting the paramterer values is straight forward, Look at this Servlet request article. Try firebug to see if the form is submitted properly.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •