codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Names for dynamically added list boxes  jennifer at 05:42 on Wednesday, February 04, 2004
 

I have a HTML form which contains a button. When the button is pressed a function is called which queries the database and displays a list box(list box populated with values from the database). This way user can add any number of list boxes.

Here is my code

client.jsp
/*************************/
<%@page contentType="text/html"%>
<html>
<head>
<script type="text/javascript" src="/forum/scripts.html"></script>
</head>
<body>
<form action="/forum/submitAddClient.html">
<div id="container"></div>
<input type="button" onclick="insSelect();" value="Add Dept" />
<input type="submit">

</form>
</body>
</html>
/*********************/
Here is scripts.jsp
/********************/

var myDataArray = new Array(
<%
con = ConnectionManager.getConnection();
stmt=con.createStatement();
rs=stmt.executeQuery("SELECT dept_name FROM department ");

while( rs.next() )
{
data = rs.getString(1);
out.println("\"" + data + "\",");
}
out.println("\"\"");
con.close();
%>
);

function insSelect()
{
var containerElement= document.getElementById("container");
var newSelectElement = document.createElement("select");
newSelectElement.name="dept_name"; //Problem Line
for (i=0; i < (myDataArray.length - 1); i++)
{

var newOptionElement = document.createElement("option");
newOptionElement.setAttribute("value", myDataArray);
newOptionElement.innerHTML = myDataArray;

newSelectElement.appendChild(newOptionElement);
}

containerElement.appendChild(newSelectElement);
}



/*************************/

This all works fine.
But there is one problem.
Each select box is created with the name "dept_name" (when the button is pressed more than once and hence there are more than one list boxes). So when i submit the form I get value of only one list box(even when there are multiple list boxes).










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: posting values from pop up window to parent window
•  Testing file for type of data
•  Running VB6 application as a ASP.NET application
•  login system with asp.net
•  Re: Help: Trouble with z-Index and SELECT lists
•  What is wrong with this ASP codes? It don`t seem to work???
•  Need help with ListBox control
•  Re: Good Javascript/DHTML Reference
•  Re: scrolling table


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2004