• Post Reply Bookmark Topic Watch Topic
  • New Topic

Add row containing dropdownlist

 
Jayasri kurra
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks good. Does it do what you expect? You might want to add a value attribute to option.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!