jsp with javascript
I have page which contion a row (3 text boxes) and a addtask (submit) button , if i press the add task button need to create a new raw with 3 more text boxes . getting some error can u help me
pls see the code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@ page
import = "java.io.*"
import = "java.lang.*"
import = "java.sql.*"
%>
<%
int task_co;
int task_lop=0;
%>
<table>
<tr><td>
Task Description</td>
<td>
             Estimated Time </td>
<td>
             Actual Time </td>
<td>
             Status </td>
</tr>
</table>
<script language="javascript" type="text/javascript">
function selected(){
document.task_co=task_co+1; ////////////// is it correct ?
}
<%
for(task_co=0;task_co==task_lop;task_lop++)
{
%>
</script>
<table>
<tr><td><input type="text" name ="task"></td>
<td><input type="text" name ="task"></td>
<td><input type="text" name ="task"></td>
<td><SELECT NAME="status">
<OPTION VALUE="task1">Pending
<OPTION VALUE="task2">Completed
<OPTION VALUE="task3">Change
<OPTION VALUE="task4">Delete
</SELECT>
</td>
</td>
<td><input type="submit" value ="Save">
</td>
</tr>
</table>
<%
}
%>
<form name="form1" method="get" action="">
<input type="button" value="Submit" onclick="selected()">
</form>
</body>
</html>
# 1
jsp scriplets will only execute once, you cannot embed them into a javascript chunk of code. the jsp scriptlets are compiled and run on the server, javascript runs on the clients browser.
you will need to do all of this in javascript or when the user submits the page have it submit to an action that can add another row of inputs and then return back to the page.
this could be tough for you if you are just a beginner.
# 2
Hi ,
Thanks for your reply ,am created text boxes with java script, then how can i handle the created text boxes in the next page ,
This is my code
--
<html>
<head>
<script>
function generateRow() {
var d=document.getElementById("div");
d.innerHTML+="<input type='text' name='task1'>";
d.innerHTML+="
";
}
</script>
</head>
<body>
<div id="div"></div>
<table>
<TR>
<TD><input type="button" value="Add" onclick="generateRow()"/></TD>
<TD><h><b><a href="http://localhost:8080/ExampleWebProject/task_cal.jsp">Submit</a></b></h></TD>
</TR>
<table>
<body>
</html>
This is the page will be called (here i want to store the )
<title>Register</title>
</head>
<body>
<%
//String[] name;
Connection dbconn;
ResultSet results;
PreparedStatement sql;
try
{
// Creating Driver class
Class.forName("com.mysql.jdbc.Driver");
try
{
dbconn = DriverManager.getConnection("jdbc:mysql://localhost:3306/MyNewDatabase","root","nbuser");
String[] name = request.getParameterValues("task1");
}
catch (SQLException s)
{
out.println("SQL Error<br>");
}
}
catch (ClassNotFoundException err)
{
out.println("Class loading error");
}
%>
</body>
</html>
Here how can i store the tasks into database , here the text boxes willl be created dynamically