• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unsure how to create and name dynamic Textfield

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
<%
}
%>
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone able to help...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hint: You used a for loop with an index to build the parameter names.
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic