• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
  • Frits Walraven
  • fred rosenberger
  • salvin francis

add list item in select field of jsp

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%@page import="java.util.Iterator"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page import="com.lb.hibernateController.GetEmployeeName" %>
<%@ page import="java.util.List" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function getEmpName(){

List<String> set = GetEmployeeName.getEmployeeName();
Iterator it = set.iterator();

String name = (String)it.next();


<s:select name="empName" label="Employee Name" onclick="getEmpName()" list="" value="#set" id="name"/>
<s:textfield name="empId" label="Employee Id" onclick="" disabled="true"/>
<s:textfield name="basicSalary" label="Basic Salary" onkeyup="getEmpName()" id="name1"/>
<s:textfield name="hra" label="HRA"/>
<s:textfield name="medicalAllowance" label="Medical Allowance"/>
<s:textfield name="educationAllowance" label="Education Allowance"/>
<s:textfield name="conveyance" label="Conveyance" />
<s:textfield name="lunchCoupon" label="Lunch Coupon" />
<s:textfield name="specialAllowance" label="Special Allowance" />
<s:textfield name="leaveEncashment" label="Leave Encashment" />
<s:textfield name="TDS" label="TDS" />
<s:textfield name="PF" label="PF" />
<s:textfield name="loan" label="Loan" />
<s:textfield name="advances" label="Advance" />
<s:textfield name="recovery" label="Recovery" />
Please tell me how to add list item in select field(Combobox) of jsp Thank You in advance**
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not 100% sure what it is your trying to do. You have an empty select box, and when you click it you want to populate that empty box with the list of names your getting back? If that is what you want then i would suggest using JQuery like in this example


Just replace the variables in the option tags with the data from your list.

Scratch that, i just realized your gonig to have issues because your javascript function has scriplets.

That is not the best solution, get rid of the scriplets. You should either
1) make and populate your employee name list a variable in your action class, then in your <s:select> box use the attribute list="myVarName". the list will read all the strings from your action class list to populate the select box.
2) If you insist on populating it from a user click, then some sort of AJAX call back to your servlet. it will return your list, probably in JSON format, then you add using the JQuery method i mentioned using the data you have.

3) If you insist on using scriplets, then inside your Iterator print out text to the HTML page in such a way as your create a local javascript array variable with all the names. Then using teh JQuery method, iterator through your created javascript array to add each option.
    Bookmark Topic Watch Topic
  • New Topic