• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Add row containing dropdownlist

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,


Can you please send the link or example as how to add a row that contains drop down list dynamically, for me the list is coming from database.

Thanks,
sri.
 
author & internet detective
Posts: 42173
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you have so far? Were you able to put the data for the drop down in a request attribute?

If so, the next step is to try write a loop that goes through the data. Look at the c:forEach tag to do this. Once you've done that, you can add the code to output <option> for each value.

Which of these steps are you stuck on?
 
Jayasri kurra
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code


<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>

<head>

<title> Add/Remove dynamic rows in HTML table </title>

<script language="javascript">

function addRow(tableID) {

var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement( '<select><option>' + item+ '</option></select>');
cell1.appendChild(element1);

}
</script>

</head>

<body>

<input type="button" value="Add Row" onclick="addRow('dataTable')" />

<input type="button" value="Delete Row" onclick="deleteRow('dataTable')" />

<table id="dataTable" border="1">

<tr>
<td valign="top">
<select NAME="choice" SIZE="5" width="20">
<c:forEach var="item" items="${list}">
<option>
<c:out value="${item}" />
</option>
</c:forEach>
</select>
</td>

</tr>
</table>

</body>

</html>

This is what I did so far.
 
Jeanne Boyarsky
author & internet detective
Posts: 42173
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks good. Does it do what you expect? You might want to add a value attribute to option.
 
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jayasri,
Can you hard code in 2 different html pages what you expect the javascript methods(addRow et deleteRow) to achieve? Please try that and post them. That way, it will be easier to work towards the solution.
 
You've gotta fight it! Don't give in! Read this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic