Hi everybody
I am a fresher. I am working in java. Totally new with java. Now I am doing one simple project. The front end consists of name and one text box for entering name. And next row consists of Id and one text box for entering id. Then I need to select subjects from a combo box. The combo box entries should come from database. That things are working properly. I want to select 5 subjects. So I have to select subject from 5 different combo boxes. I gave same name for each combo box. And used java script for dynamically adding rows. That also working properly. Then I have a table in database to insert these values. My table has seven column withn column names Name,Id,Subject 1,Subject2,Subj ect3,Subject4,S ubject5. Name,Id are coming correctly into database. however same subjects are coming into all columns of table eventhough i select different subject names.Only first subject is ncoming into each column. I know the problem also. That is because I have given same name for each combo box. I am using oracle database.
I am giving my jsp page below.
java script for dynamically adding rows
front end design
Please help me.
Thanks.
I am a fresher. I am working in java. Totally new with java. Now I am doing one simple project. The front end consists of name and one text box for entering name. And next row consists of Id and one text box for entering id. Then I need to select subjects from a combo box. The combo box entries should come from database. That things are working properly. I want to select 5 subjects. So I have to select subject from 5 different combo boxes. I gave same name for each combo box. And used java script for dynamically adding rows. That also working properly. Then I have a table in database to insert these values. My table has seven column withn column names Name,Id,Subject 1,Subject2,Subj ect3,Subject4,S ubject5. Name,Id are coming correctly into database. however same subjects are coming into all columns of table eventhough i select different subject names.Only first subject is ncoming into each column. I know the problem also. That is because I have given same name for each combo box. I am using oracle database.
I am giving my jsp page below.
java script for dynamically adding rows
Code:
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
//alert("rowCount"+rowCount);
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
//alert("colCount :"+colCount);
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "label":
//alert(newcell.childNodes[0].type);
newcell.childNodes[0].value = "";
break;
case "select-one":
//alert(newcell.childNodes[0].type);
newcell.childNodes[0].selectedIndex = 0;
newcell.childNodes[0].id = 'sub'+rowCount;
break;
}
}
}
Code:
<form id="form2" name="form2" method="post" action="homeServlet" >
<table>
<tr>
<th>Name</th>
<td><input type="text" name="Name"/></td>
</tr>
<tr>
<th>Id</th>
<td><input type="text" name="Id"/></td>
</tr>
<tr><td>
<table id="dataTable">
<tr>
<td>Subject
</td>
<td><select name="sub" style="width:150px;">
<%ArrayList<String> al=null;
al=(ArrayList<String>)arr;
int count= arr.size();
System.out.println("Subject count:"+count);
if(!al.isEmpty())
{
%>
<option value="select" selected>----select one option----</option>
<% for(int i=0;i<count;i++) { %>
<option value="<%=al.get(i)%>"><%=al.get(i)%>
</option> <% } } %>
</select></td>
</tr>
</table></td></tr>
</table>
<a href="javascript:addRow('dataTable');"><b>Add Subject</b></a><br/><br/>
<input type="submit" value="submit" onclick="Second.jsp"/>
Please help me.
Thanks.
Comment