here I would like to execute both javascript and JSP after onclick event
<CODE>
<table id = "add_degree">
<tbody>
<tr>
<td>
<%rs2 = st.executeQuery("Select * from degrees"); %>
<select name = "courses">
<%while(rs2.next()) {%>
<option value = "<%=rs2.getString(1)%>"><%=rs2.getString(2)%></option>
<%} %>
</select>
</td>
<td>
<input type = "text" name = "ratings" class = "span1">
</td>
<td>
<a href = "">Delete Course</a>
</td>
</tr>
</tbody>
</table>
Here onclick event adds a new row to the existing table with similar cell blocks.
I have a JSP code which enters the row data into database.
Can I make execute both JSP and javascript code simultaneously so that I have a new row and the data entered in the previous is entered into the database.
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "button":
newcell.childNodes[0].value = "Delete Course";
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
If you can use jQuery (best choice nowdays, anyway)
Don’t forget to construct addToDatabase.jsp in such a way, that
data, passed to success function, gives you information if the row was trully added to database.Probably you need to pass some parameters to addToDatabase.jsp, how to do it is described in jQuery reference guide.