*
The moose likes JSP and the fly likes Unsure how to create and name dynamic Textfield Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Unsure how to create and name dynamic Textfield" Watch "Unsure how to create and name dynamic Textfield" New topic
Author

Unsure how to create and name dynamic Textfield

vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
I'm trying to create a list to record student grades into the database. I'm able to pull out the names from the database and create a table with textfields in it to input the data into. But all the textfields have the same name. Due to this i'm unable to do a

String textbox = request.getParameter("textbox");

This is my code, please advice accordingly. Thank you for your assistance.


<%
while(rst2.next()){
Childic = rst2.getString("Childic") ;

%>
<tr>
<th scope="col">&nbsp;</th>
<th scope="col"><%=Childic%></th>
<th scope="col"><input name="ca1" type="text" id="exam1" size="7" /></th>
<th scope="col"><input name="ca2" type="text" id="exam2" size="7" /></th>
<th scope="col"><input name="ca3" type="text" id="exam3" size="7" /></th>
<th scope="col"><input name="ca4" type="text" id="exam4" size="7" /></th>
<th scope="col">&nbsp;</th>
</tr>
<%
}
%>
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
Thank you for your help Ben Souther. I'm sorry but i have another question. How do i save the values into a database. I cant use

String textbox = request.getParameter("textbox");

My database fields are exam1, exam2, exam3, exam4
vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
Anyone able to help...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by vanan saravanan:
... How do i save the values into a database[?] ...


This question is a bit beyond the scope of a JSP forum.
I would start with a Google search for "JDBC TUTORIAL".
There are a lot of them out there.

Once you're comfortable writing small, standalone Java objects that can read and write from your database, try a Google search for "JSP TUTORIAL JAVABEANS" to learn how to incorporate your database code into your webapp.

-Ben
vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
I do know how to read and write to the database. Only for dynamic textbox i'm not too sure hoe to script my code.

for(int i = 0; rst2.next(); i++){
.......
<th scope="col"><input name="ca1_<%=i%>" type="text" id="exam1" size="7" /></th>
...


String textbox = request.getParameter("textbox"); Wont work as i need to get the values from all the dynamic fields.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Hint: You used a for loop with an index to build the parameter names.
vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
This is what i've tried.

for(int i = 0; rst2.next(); i++){
String ca1 = request.getParameter("ca1_<%=i%>");
String query2 = "INSERT into results(ca1) values ('"+ca1+"')";
stm2.executeUpdate(query2);
}


The error as follows..

String not terminated at end of line.
String ca1 = request.getParameter("ca1_<%=i
vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
Problem solved.

for(int i = 0; rst2.next(); i++){
String ca1 = request.getParameter("ca1_"+i);
String query2 = "INSERT into results(ca1) values ('"+ca1+"')";
stm2.executeUpdate(query2);
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unsure how to create and name dynamic Textfield