HI,

I wish to get the values from the drop down menu selected by a user from the HTML page and pass this value into my servlet program for processing.

In my servlet program, I've used the getParameter() function to obtain the value from the drop down menu selected.


<SELECT name=Day>
<OPTION value="" selected>- Select -</OPTION>
<OPTION value=Sunday>Sunday</OPTION>
<OPTION value=Monday>Monday</OPTION>
<OPTION value=Tuesday>Tuesday</OPTION>
<OPTION value=Wednesday>Wednesday</OPTION>
<OPTION value=Thursday>Thursday</OPTION>
<OPTION value=Friday>Friday</OPTION>
<OPTION value=Saturday>Saturday</OPTION>
</SELECT>


String days= request.getParameter("Day");
System.out.println("DAY =" +days);

However, the value of the parameter "day" seems empty. May I know what is the correct method of getting the value selected from the drop down menu into my servlet? It did work when I use Javascript functions to extract it though (function getDay() in frmLockOut.html).

Attached are my JSP(frmLockOut.html) and Servlet(AdmProfileLockOut.java- see function add( ) ) source code files for reference.

Thanks
Danny

Attachments
/******************************************************************************************/
/* Written by : ADMIN                                                                     */
/* Date : 30 JULY 2004 , 2.51PM                                                            */
/* Modified by : CJ 																	   */
/* Date : Jan 10 2005																	   */
/******************************************************************************************/
import java.io.*;
import java.net.*;
import java.util.*;
import com.protea.db.*;
import com.eprotea.util.*;
import com.protea.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class AdmProfileLockOut extends HttpServlet {
	
	class MyParam {
		Properties requestProp = new Properties ();	
	}

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        processRequest(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        processRequest(request, response);
    }
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

       String task = request.getParameter("_taskType"); //hidden type;
       if(task.equals("N")){
           add(request, response);
       }else if(task.equals("D")){
           delete(request, response);
       }else if(task.equals("U")){
           edit(request, response);
       }else{
           request.setAttribute("errorTask","Profile Maintenance");
           request.setAttribute("errorProc","Request Task Type");
           request.setAttribute("errorMsg", "Invalid Task Type");
           RequestDispatcher rd = getServletContext().getRequestDispatcher("ErrorPage.jsp");
           try{
                rd.forward(request, response);
           }catch(Exception e){
                e.printStackTrace();
           }
           return;
       }
    }

private void promptError (HttpServletRequest request, HttpServletResponse response, MyParam myparam) 
throws Exception {
	String qString = "?";
	for (Enumeration enum = myparam.requestProp.propertyNames();enum.hasMoreElements();) {
		String key = (String)enum.nextElement();
		String val = myparam.requestProp.getProperty (key);
		qString += key+"="+val+"&";
	}
	qString += "error=1";
	response.sendRedirect("../admin/frmLockOutMaint.jsp"+qString);
	return;
}

private void promptAnonymous (HttpServletRequest request, HttpServletResponse response, String procedure, String msg) {
	request.setAttribute("errorTask","Profile Maintenance");
   	request.setAttribute("errorProc",procedure);
   	request.setAttribute("errorMsg", msg);
   	RequestDispatcher rd = getServletContext().getRequestDispatcher("ErrorPage.jsp");
   	try{
        rd.forward(request, response);
   	}catch(Exception e){
        e.printStackTrace();
   	}
   	return;
}

private void returnTrue (HttpServletRequest request, HttpServletResponse response, MyParam myparam) 
throws Exception {	

	String qString = "?";
	for (Enumeration enum = myparam.requestProp.propertyNames();enum.hasMoreElements();) {
		String key = (String)enum.nextElement();
		String val = myparam.requestProp.getProperty (key);
		qString += key+"="+val+"&";
	}
	response.sendRedirect("../admin/frmLockOutMaint.jsp"+qString);
	return;
}

private void printQString (HttpServletRequest request) {
	for (Enumeration enum = request.getParameterNames (); enum.hasMoreElements();) {
		String name = (String) enum.nextElement();
		String val [] = request.getParameterValues (name);
		System.out.println ("NAME = "+name);
		for (int i=0;i<val.length;i++) {
			System.out.println ("VALUE = "+val[i]);
		}
	}
}

/*private void validTimes(String startTime,String endTime,HttpServletRequest request, 
HttpServletResponse response, MyParam myparam)
{
	  MyParam myparam = new MyParam();
      if(startTime.compareTo(endTime)>0){
	     myparam.requestProp.setProperty ("_timeErr","Start Time cannot be greater than End Time");
	     promptError(request, response, myparam);
	     // request.setAttribute("errorMessage", "End Time must be greater than Start Time");
	     RequestDispatcher rd = getServletContext().getRequestDispatcher("ErrorPage.jsp"); 
      }
      returnTrue(request, response, myparam);         
}*/

    /******************************************************************************************/
    /* add Profile table here                                                                    */
    /******************************************************************************************/
private void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(false);
		String profileId = null;
		String desc = null;
        String time = null;
        String display = null;
        String indicator = null;
        
        String updUserId = (String) session.getAttribute("userId");
        String busRegNo = (String) session.getAttribute("busRegNo");
        
        String days= request.getParameter("Day");
        
        String startTime = request.getParameter("_startTimeDesc");
        String endTime = request.getParameter("_endTimeDesc");
        
        MyParam myparam = new MyParam();
		
        profileId   = request.getParameter("_txtProfileID");
        
        System.out.println("profileId = "+profileId);
        
        desc 			= request.getParameter("_txtProfileDesc").toUpperCase();
        
        time 			= DateConvert.getTodayDateTime();
        
        CommDB db            = new CommDB();

        String tblName       = "PGM_PROFILE";  //contents based on "Enquiry" button evt
        String tblFieldsName = "C_BUS_REG_NO, C_PRO_FILE_ID, C_CRE_TMS, C_UPD_UID, C_UPD_TMS, V_DESC";
        String tblFieldsData = db.format(busRegNo)+","+ 
        					   db.format(profileId)+","+
        					   db.format(time)+","+
        					   db.format(updUserId)+","+
        					   db.format(time)+","+
        					   db.format(desc);
 
		//FOR UPDATING BPFILE_TASK TABLE
		 
        String fieldNameBPFILE_TASK ="C_BUS_REG_NO, C_PRO_FILE_ID, C_DAY_OF_WEEK, S_TASK_ID, S_STRT_TM, S_END_TM, C_CRE_TMS, C_UPD_UID, C_UPD_TMS";         
                							  
        db.setDebug(true);
        System.out.println("HERE ... \n");
		System.out.println ("QUERYSTRING "+request.getQueryString());
        
        try{
	        db.startTransaction();

	        db.query ("select * from PGM_PROFILE where C_PRO_FILE_ID="+db.format(profileId)+"");
	        if (db.getNumberOfRows()>0) {
		        myparam.requestProp.setProperty ("_txtProfileIdErr","Profile ID already exist.");
		        myparam.requestProp.setProperty ("_rdProfileID",profileId);
		        myparam.requestProp.setProperty ("profileDesc",desc);		        
		        promptError (request, response, myparam);
		    } else {
		        db.insert ("PGM_PROFILE", tblFieldsName, tblFieldsData);

                 
                db.query("select s_task_id, c_pro_file_id from BPFILE_TASK where c_pro_file_id='"+profileId+"'");
                
                printQString (request);
                
		        String taskIds[] = request.getParameterValues("TaskId");
				System.out.println("LEN = "+taskIds.length);
				
		         //handles selected task records. 
		        
		        for(int i=0;i<taskIds.length; i++){
		           String fieldsBPFILE_TASK = db.format(busRegNo)+","+
        							  db.format(profileId)+","+
        							  db.format(days)+","+
        							  db.format(taskIds[i])+","+
        							  db.format(startTime)+","+
        							  db.format(endTime)+","+
        							  db.format(time)+","+
        							  db.format(updUserId)+","+
        							  db.format(time);
                
			        db.insert("BPFILE_TASK", fieldNameBPFILE_TASK, fieldsBPFILE_TASK);
		        }
		        			   	
		        db.endTransaction (true);
		        
		        myparam.requestProp.setProperty ("_txtProfileID",profileId);
		        myparam.requestProp.setProperty ("doAct","0");
		        returnTrue (request, response, myparam);
			}
	    }catch (Exception e){
		    db.endTransaction (false);
		    e.printStackTrace ();
		    //promptAnonymous (request, response, "Profile Maintenance Add", e.getMessage());
		    promptAnonymous (request, response, "Profile Maintenance LockOut-Assignment", "error during Add()");
		}
}


private boolean isConcurrent (CommDB db, String profileId, String updtms) throws Exception {
    //This method is called in delete().

    //checks if record with a particular ID and timestamp exists prior to deletion.
	db.query ("select * from PGM_PROFILE where C_PRO_FILE_ID='"+profileId+"' and C_UPD_TMS='"+updtms+"'");

	if (db.getNumberOfRows()==0){
 		return false;
	}
    return true;
}

    /******************************************************************************************/
    /* delete Profile table here                                                                 */
    /******************************************************************************************/
    private void delete(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String profileId   	= request.getParameter("_txtProfileID");
        String updtms 		= request.getParameter ("updTm");

        CommDB db      = new CommDB();
        try {
            db.startTransaction();

            //check for concurrency in timestamp updates.
            if (isConcurrent(db, profileId, updtms)) {
	            db.delete("PGM_PROFILE", "C_PRO_FILE_ID='"+profileId+"'");
                
                db.delete("BPFILE_TASK","C_PRO_FILE_ID="+db.format(profileId));
                //db.delete("BPGM_TASK ");
	            //every start of a transaction should be accompanied with an end of a transaction.
	            //Ended transaction with a "true" flag if record is successfully deleted.
	            db.endTransaction(true);
	        } else {
		        //delete op failed. Transaction ended with a false flag.
	            db.endTransaction(false);
	            response.sendRedirect("../ad
<!--formerly S4.html -->
<%@ page session = "false"%>
<%@ page import="com.protea.db.*,com.eprotea.util.*,java.util.*, java.io.*, java.lang.*" %>
<jsp:useBean id="db" class = "com.protea.db.CommDB"/>

<%
   
   response.setHeader("cache-control", "no-cache");
   HttpSession	session = request.getSession(false);
   String userId = (String)session.getAttribute("userId");
   String busRegNo = (String)session.getAttribute("busRegNo");
   String groupId = (String)session.getAttribute("groupId");

   String mode = request.getParameter ("mode")==null?"":request.getParameter ("mode");
   String timeStamp = request.getParameter("updtms")==null?"":request.getParameter("updtms");
   
   
   String profileId = request.getParameter("_txtProfileID")==null?"":request.getParameter ("_txtProfileID");
   
   
   //CHECK DESC LATER - PASSED INTO WRONG PLACE.
   String profileDesc = request.getParameter("_txtProfileDesc")==null?"":request.getParameter ("_txtProfileDesc");
   
   
   
   
   Vector availTask = new Vector();
   Vector selectedTask = new Vector();
   
   availTask = getAvailBPGMTask();
   
   
   if(!mode.equals("N")){
      selectedTask = getSelectedBPGMTask();
   }
   
	Vector profDescVect = new Vector();
   	profDescVect = getProfDesc(profileId);
   	out.println("profDescVect size = "+profDescVect.size());   
   	
   	
	if(mode.equals("N")){
		profileDesc=" ";
    }		
	
   
%>

<%!
   /*private String getMode(){
      return request.getParameter("mode")==null?"":request.getParameter ("mode");	   
       
   }*/	   	
   
   /*private String getTimeStamp(){
      return request.getParameter("updtms")==null?"":request.getParameter("updtms");	   
   }*/	   
      
   private Vector getAvailBPGMTask() throws Exception{
	//this function loads all task description along with their task IDs into the 
	//"Available Task" list during Lock-out.  	   
	
   		CommDB db = new CommDB();
   		db.query("select distinct S_TASK_ID, v_desc from BPGM_TASK");
   		return new Vector(db.getData());   
   }	
   
   private Vector getSelectedBPGMTask() throws Exception{
      CommDB db = new CommDB();
      db.query("select distinct s_task_id from BPFILE_TASK");
      return new Vector(db.getData());	   
   }	
         
   //for displaying profileId description into desc field, carried from frmProfileMaint.jsp
   private Vector getProfDesc(String profileId) throws Exception{
	   CommDB db = new CommDB();
	   db.query("select v_desc from pgm_profile where c_pro_file_id='"+profileId+"'");
	   return new Vector(db.getData());
   }   
   
   /*private String getStartTime(){
      return request.getParameter("_startTimeDesc")==null?"":request.getParameter("_startTimeDesc");	   
   }*/	   
   
   /*private String getEndTime(){
      return request.getParameter("_endTimeDesc")==null?"":request.getParameter("_endTimeDesc"); 	   
   }*/
   	   	   
   private String setBlank(String val){
	if(val==null)
		return "";
   	return val;
   }
   
   
   private void displayTimes(String start, String end){
      System.out.println("StartTime = "+start+" End Time = "+end);	  
   } 

   
   
%>

<%
   String startTime = request.getParameter("_startTimeDesc")==null?"":request.getParameter("_startTimeDesc");
   String endTime = request.getParameter("_endTimeDesc")==null?"":request.getParameter("_endTimeDesc");
   displayTimes(startTime, endTime);
   //String day = request.getParameter("Day");
   
   //showDay(day);
%>   

<html>
<head>
<title>Profile Profile Maintenance - LOCK-OUT_ASSIGNMENT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../css/iscap.css" type="text/css">
<script language="JavaScript" src="../js/general.js"></script>
<script language="JavaScript" src="../js/validator.js"></script>
<script language="JavaScript" src="../js/scrollTable.js"></script>
<script language="JavaScript1.2" src="../js/jSelector.js"></script>
<SCRIPT language="javascript">
window.status = "BANK NEGARA MALAYSIA - ISCAP Application System  Email: iscap@bnm.gov.my ";


<!--Javascript function to check time validity -->

function selectAllTo() {	
	selectAllElement(document.frmLockOutOp.Available);		
	selectTo();
}
	
function selectTo() {		
	addElement (document.frmLockOutOp.Available, document.frmLockOutOp.selectedTask);
}
	
function selectAllFrom() {
	selectAllElement(document.frmLockOutOp.selectedTask);
	selectFrom();
}
	
function selectFrom() {
	addElement(document.frmLockOutOp.selectedTask, document.frmLockOutOp.Available);
}


function goCancel() {

  var f = document.frmLockOutOp;
  f.method="POST";
  f.action="../admin/frmLockOutMaint.jsp";
  f.target="_self";
  f.submit();
}


function goReset(){
  var f = document.frmLockOutOp;
  f._txtProfileID.value = "";
  f._txtProfileDesc.value = "";
  f._txtProfileID.focus();
}

function loadProgram(){
   var f = document.frmLockOutOp;
   // alert(f.Available.length);
   // frm.Available.length = 0;	
   	<% for (int i=0;i<availTask.size() / 2;i++) { %>
// 	    alert("<%=availTask.elementAt(i * 2)+" - "+availTask.elementAt(i * 2+1)%>");
   	 	f.Available[<%=i%>] = new Option ("<%=availTask.elementAt(i * 2)+" - "+availTask.elementAt(i * 2+1)%>","<%=availTask.elementAt(i*2)%>");
   	<% } %>	
}	

function Loading(){
	var f = document.frmLockOutOp;
	f._txtProfileID.focus();
	
	if(0 == "1"){
		f._hidProfileID.value = "**Duplicate Profile ID";
	}
	loadProgram();
}

function go(){
	  var f = document.frmLockOutOp;
	  f.method="POST";
	  f.action="frmLockOutMaint.jsp";
	  f.target="_self";
	  f.submit();
}

<!--CJ-->
function goDelete(){
	  var f = document.frmLockOutOp;
	
	    f.mode.value = "D";
	    f.method="POST";
	    
	  //f.action="../servlet/AdmProfileMaint";
	  //f.action="frmProfileMaintAdd.jsp";
	  f.target="_self"; 
	  
	  confirmDel();
	 
	  f.submit();	  
}

function goSave() {
  
  var f = document.frmLockOutOp;
  
  if(f._txtProfileID.value ==""){
	  alert('Please fill in the Profile ID.');
	  f._txtProfileID.focus();
	  return false;
  }
  if(isCharNum(f._txtProfileID) == false){
	  f._txtProfileID.focus();
	  return false;
  }

  if(f._txtProfileDesc.value == ""){
	  alert('Please fill in the Profile Description.');
	  f._txtProfileDesc.focus();
	  return false;
  }

  if(f.mode.value=="D"){
     confirmDel();
  }    
  
  //CJ - saves all selected ISCAP program wrt profileID into NOT_ALLW_BPGM db.
  
  ///GET DAY ///////////////
  getDay();
  
  submitSelectedTask();
  
  f.method="POST";
  f.action="../servlet/AdmProfileLockOut";
  //f.action="frmProfileMaintAdd.jsp";
  f.target="_self";
  f.submit();
}

<!--CJ -->
function submitSelectedTask () {
	var f=document.frmLockOutOp.selectedTask;
	var s=document.frmLockOutOp;	
	
	var arr = new Array(f.length);
    for(var i=0; i<f.length; i++){
	   document.frmLockOutOp.selectedTask.options[i].selected = true;
	   arr[i] = eval("document.frmLockOutOp.selectedTask.options["+i+"].text");
       arr[i] = eval("document.frmLockOutOp.selectedTask.options["+i+"].value");	   
       alert("Array["+i+"] = "+arr[i]);
    }
}


function confirmDel(){
   var f = document.frmLockOutOp;
   
   f.mode.value="D";
   f.methd="POST";
   f.target=self;
   
   var answer = confirm("Deleting "+f._txtProfileID.value);
   if(answer){
      return true;	 
   }	     
   else{
	  f.action="../admin/frmLockOutMaint.jsp";
      return false;	   
   }   	
}

function getDay(){
   var f = document.frmLockOutOp;
   alert("MODE = "+f.mode.value);
   choice = f.Day.options[f.Day.selectedIndex].value;
   alert("DAY selected = "+choice);	
}	

function disableMoveButtons(){
	//Have to call this function during load time - ensures that buttons
	//would be disabled automatically during delete mode. Hence, not at submit() time. 
	
	var f = document.frmLockOutOp;
	if(f.mode.value=="D"){
	   f.allTo.disabled =true;
	   f.allFrom.disabled =true;
	   f.leftByOne.disabled = true;
	   f.rightByOne.disabled = true;
	}		 
}	

function isTime(d){
  var pattern = new Object();
  pattern.Time=/^((2[0-3]|0[0-9]|1[0-9])+:+([0-5][0-9]))$/;
  var time = d.value;
  var min = time.substring(3,5);
    
  if(d.value==""){
    return;
  }
  else if (min>="60"){
  	alert("Invalid time");
    d.value = "";
    d.focus();
	return;
  }
  else if (!pattern['Time'].test(d.value)){
    alert("Time is in 24 hours format (xx:xx)");
    d.value = "";
    d.focus();
    return;
  }
  else{
    return;
  }
}


</script>
</head>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff onload="Loading();disableMoveButtons();">
<FORM name=frmLockOutOp action="" method=post>
<SPAN class=pathTitle>Administration -&gt; Maintenance -&gt; Profile Maintenance -&gt; Add</SPAN> 
<BR>
<TABLE class=doubleBorder width="100%" align=center border=0>

<input type="text" name="mode" value="<%=mode%>">
<input type="text" name="updTm" value="<%=timeStamp%>">

  <TBODY>
  <TR>
    <TD>
      <TABLE width="50%" align=center border=0>
       <TBODY>
        <TR>
          <TD width="20%">Profile : </TD>
          <TD width="30%">
          <INPUT class="inputField" name="_txtProfileID" onblur="toUpper(this)"; <%if(mode.equals("U") || mode.equals("D")){%>value="<%=profileId%><%}%>" tabindex="1" <%if(mode.equals("U")||mode.equals("D")){%> readonly <%}%>></TD>
        </TR>
   		<TR>
         <TD width="20%">Program Description :</TD>
         <TD width="30%">
         <input type="text" name="_txtProfileDesc" value="<%=(String)profDescVect.elementAt(0)%>" class="inputField" maxlength="50" onBlur="toUpper(this);" tabindex="2" <%if(mode.equals("D")){%>readonly<%}%>>
         
        </TR>
        <TR>
        </TR>
       </TBODY>
      </TABLE>
    </TD>
  </TR>
  </TBODY>
</TABLE>
<TABLE width="70%" align=center border=0>
<br/>
  <TBODY>
  <TR>
    <TD width="5%">Day</TD>
    <TD>:</TD>
    <TD colSpan=3>
    <SELECT name=Day> 
    <OPTION value="" selected>- Select -</OPTION> 
    <OPTION value=Sunday>Sunday</OPTION> 
    <OPTION value=Monday>Monday</OPTION> 
    <OPTION value=Tuesday>Tuesday</OPTION> 
    <OPTION value=Wednesday>Wednesday</OPTION> 
    <OPTION value=Thursday>Thursday</OPTION>
    <OPTION value=Friday>Friday</OPTION>
    <OPTION value=Saturday>Saturday</OPTION>
    </SELECT> 
    </TD>
    <TD w

Don't attach things, I won't open them.

Most likely you didn't place the select inside an html form which would cause the value to not be passed in the request.

Hi , all
Can anyone please tell me how to get multiple values from a drop down menu . I know that we have to specify MULTIPLE in SELECT tag
This is my simple code, I wnat to display selected values in dd.jsp , if anyone can help me ,, PLEASE DO IT SOOON..

<FORM Action="dd.jsp">
<SELECT NAME="drop" SIZE=3 multiple>
<OPTION> Authoring
<OPTION> Internet
<OPTION> Location
<OPTION> Multimedia
<OPTION> Reference
<OPTION> Software
</SELECT>

<input type ="submit">
</FORM>

PLEASE DO IT SOOON
Wrong way to ask a question. We're not here to do your bidding at your whim. Maybe you should have started researching sooner if you're in a hurry now.

the multiselect is not possible with a dropdown, only with a selectbox.

You can get the values with getParameterValues(String) on the ServletRequest.
The API docs will give you more information.

hey , thanks very much for your reply..!!! I had already solved it but you were absolutely correct about getParameterValues() ..I appreciate your knowledge.
Thanks Again...

You should be creating a new topic for a new question. You also might want to be asking this question in the JavaScript forum.

Regards,

Nate

Hi,
Try this, it works for me :D

<% String days= request.getParameterValues("Day"); %>

lets say I have a select box like

<SELECT id="MySelect" multiple >
  <option value="A">Text 1<option>
  <option value="B">Text 2<option>
  <option value="C">Text 3<option>
</SELECT>

ok now if I want to get all the selected values of this multiple select box I just call :-

String[] arrValues[] = objRequest.getParameterValues("MySelect");

but now my problem is how do I get the text values.

I know in JavaScript I can get both the text and the values by just issuing :-

document.getElementById("MySelect").value;
document.getElementById("MySelect").text;

but how do I do this in Servlet, how do I do this in J2EE programmming ? :!:

How do I get the selected text value ?

Hi,
Try this, it works for me :D

<% String days= request.getParameterValues("Day"); %>

Mine doesn't work, whats wrong?


<select name="mySelection">
<option value ="Nairobi" selected>Nairobi</option>
<option value ="Central">Central</option>
<option value ="Central">Coast</option>
<option value ="Eastern">Eastern</option>
<option value ="North Eastern">North Eastern</option>
<option value ="Nyanza">Nyanza</option>
<option value ="Rift Valley">Rift Valley</option>
<option>Western</option>
</select>
<%
<% String[] province = request.getParameterValues("mySelection");%>

you have not written multiple in <select>...see previous posts for better understanding...your code should have been smthing like this

<select name="abc" multiple>
<!-- whatever option you want to put in-->
</select>

HI,

I wish to get the values from the drop down menu selected by a user from the HTML page and pass this value into my servlet program for processing.

In my servlet program, I've used the getParameter() function to obtain the value from the drop down menu selected.


<SELECT name=Day>
<OPTION value="" selected>- Select -</OPTION>
<OPTION value=Sunday>Sunday</OPTION>
<OPTION value=Monday>Monday</OPTION>
<OPTION value=Tuesday>Tuesday</OPTION>
<OPTION value=Wednesday>Wednesday</OPTION>
<OPTION value=Thursday>Thursday</OPTION>
<OPTION value=Friday>Friday</OPTION>
<OPTION value=Saturday>Saturday</OPTION>
</SELECT>


String days= request.getParameter("Day");
System.out.println("DAY =" +days);

However, the value of the parameter "day" seems empty. May I know what is the correct method of getting the value selected from the drop down menu into my servlet? It did work when I use Javascript functions to extract it though (function getDay() in frmLockOut.html).

Attached are my JSP(frmLockOut.html) and Servlet(AdmProfileLockOut.java- see function add( ) ) source code files for reference.

Thanks
Danny

Please give name value of select tag in double quotes

HI,

I wish to get the values from the drop down menu selected by a user from the HTML page and pass this value into my servlet program for processing.

In my servlet program, I've used the getParameter() function to obtain the value from the drop down menu selected.


<SELECT name=Day>
<OPTION value="" selected>- Select -</OPTION>
<OPTION value=Sunday>Sunday</OPTION>
<OPTION value=Monday>Monday</OPTION>
<OPTION value=Tuesday>Tuesday</OPTION>
<OPTION value=Wednesday>Wednesday</OPTION>
<OPTION value=Thursday>Thursday</OPTION>
<OPTION value=Friday>Friday</OPTION>
<OPTION value=Saturday>Saturday</OPTION>
</SELECT>


String days= request.getParameter("Day");
System.out.println("DAY =" +days);

However, the value of the parameter "day" seems empty. May I know what is the correct method of getting the value selected from the drop down menu into my servlet? It did work when I use Javascript functions to extract it though (function getDay() in frmLockOut.html).

Attached are my JSP(frmLockOut.html) and Servlet(AdmProfileLockOut.java- see function add( ) ) source code files for reference.

Thanks
Danny

try this one:
1) capture the value of the dropdown select box with javascript using the getElementById command.
2) then next step to do is simply pass the value captured to the servlet. thats all! its gonna work! I guarantee you!

try this one:
1) capture the value of the dropdown select box with javascript using the getElementById command.
2) then next step to do is simply pass the value captured to the servlet. thats all! its gonna work! I guarantee you!

First of all this thread is 5 years old.
Second what you said is not necessary for the solution. The html code is correct and all is needed is to submit the form. You don't need javascript in order to put the value to another field and send that.

If you have read the entire you would know what was the problem.


And it is time to close this thread, before another tries to post their own crazy idea.

This question has already been answered. Start a new discussion instead.