Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get the id /value of the checkBox

 
tashu Bairy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all
I have a problem . I am having html code genereation in the servlet where i have a checkbox , which when clicked will pass on the id , i am not able to do that, here is the code
pw.println( "<TD>" );
pw.println( "<input type=\"checkbox\" name=\"chkTsk\" value=\"");
pw.println(task.getId());
pw.println( "\"");
pw.println( " unchecked>" );
pw.println( "</TD>" );


when the ckeckbox is checked, its not being able to take the id. What could be the problem & solution?
Thanks
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before submitting the form, do a 'View Source'. Do you see the ID in the form?
 
tashu Bairy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, i do see the id in the view source. But the problem is there is more than one check boxes in the form, i might check few of them & then submit the form, while parsing the valuesi.e id associated with those check boxes, its giving arrayoutofindex error for those checkboxes which r not checked,
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you send the following code snippets:
1. HTML View Source (just the parts with the checkboxes)
2. JSP/Servlet Code (just the part that is trying to retrieve the checkbox parameters)

Note that this forum allows for UBB Code. There are buttons just below the text area where you can wrap items in the 'code' tags. That way, it is easier to read the code.
[ June 27, 2005: Message edited by: Sharad Agarwal ]
 
tashu Bairy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<FORM ACTION="/ResourceManagerWS/dratask" METHOD="POST">
<TR>
<TR>
<TD>
<input type="checkbox" name="chkTsk" value="
110
"
unchecked>
</TD>










String button = req.getParameter( "TaskSubmit");
if(button!=null&&button.equalsIgnoreCase( "submit")){
String[] chkBxValues = req.getParameterValues("chkTsk");
String[] lstBxValues = req.getParameterValues("status");
String[] txtBxValues = req.getParameterValues("reason");

for(int i=0;i<txtBxValues.length ;i++){
if(!(txtBxValues[i].equals(""))){

String chkBxValue=chkBxValues[i].trim();
String lstBxValue=lstBxValues[i];
String txtBxValue=txtBxValues[i];
long tskId= Long.valueOf(chkBxValue.trim()).longValue();
Task tb=WMHelper.getTask(tskId);
tb.setCompletionExplanation(txtBxValue);
}
}
}
tx.commit();
}
catch( Exception e )

if the first checkbox is clicked then pgm works well, if first is not checked & any checked there on , gives
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tashu db:

String[] chkBxValues = req.getParameterValues("chkTsk");
String[] txtBxValues = req.getParameterValues("reason");

for(int i=0;i<txtBxValues.length ;i++){
if(!(txtBxValues[i].equals(""))){

String chkBxValue=chkBxValues[i].trim();
String txtBxValue=txtBxValues[i];
long tskId= Long.valueOf(chkBxValue.trim()).longValue();
}
}


I have snipped through your code a bit to focus on the problem area. Note that you have a loop of size txtBxValues.length and you are trying to use the iterator as index for the chkBxValue array.

Naturally, if (chkBxValue.length < txtBxValues.length), your code could fail. I hope this will help you fix your issue.
 
tashu Bairy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sharad
Thank you so much for your help. Infact the problem was infact the one you had mentioned
 
Sharad Agarwal
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad I could help. Keep coding and keep asking!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic