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>

&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp &nbsp&nbsp Estimated Time </td>

<td>

&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp &nbsp&nbsp Actual Time </td>

<td>

&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp &nbsp&nbsp 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>

[2270 byte] By [rayees1234a] at [2007-11-27 8:43:21]
# 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.

den2681a at 2007-7-12 20:43:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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

rayees1234a at 2007-7-12 20:43:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

when you create your new table rows you'll want to give the inputs names like "taskDesc1", "taskDesc2", "taskDesc3"...... then on your next page keep checking for parameters named "taskDescX" where X goes from 1 - N. the first time you hit a null you'll know that was the max rows sent.

or, you could make another form variable that says exactly how many rows there are and pass that to the next .jsp. using that value you'll know how many params to look for.

den2681a at 2007-7-12 20:43:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
or name them the same thing and make it an array on the form. It would then be submitted as an array.
gmachamera at 2007-7-12 20:43:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...