reset password
Author Message
afetiso
Posts: 84
Posted 23:08 Jan 23, 2014 |

in example we have

entry.setPre( request.getParameter( "pre" ) );

but this for text field. What we need to chuse for

entry.setPre ( ????????? ) for use "velue" of checked boxes

cshah6
Posts: 19
Posted 23:16 Jan 23, 2014 |

You need to get the value of checkboxes by using 

request.getParameterValues("??");

 

 

xytian
Posts: 70
Posted 23:19 Jan 23, 2014 |

As cshah6 said.

Last edited by xytian at 23:23 Jan 23, 2014.
afetiso
Posts: 84
Posted 23:26 Jan 23, 2014 |

thank you fix it, just need to nameall checkboxes the same =  "checkbox"  and use:

String[] check = request.getParameterValues( "checkbox" );

afetiso
Posts: 84
Posted 23:26 Jan 23, 2014 |

thank you fix it, just need to nameall checkboxes the same =  "checkbox"  and use:

String[] check = request.getParameterValues( "checkbox" );

kaancalstatela
Posts: 52
Posted 18:40 Jan 24, 2014 |

thank you fix it, just need to nameall checkboxes the same =  "checkbox"  and use:

String[] check = request.getParameterValues( "checkbox" );

 

This didn't work at all for me. I'm struggling with this at the moment. I'll try to come up with a solution.

kaancalstatela
Posts: 52
Posted 18:55 Jan 24, 2014 |

I think I fixed it by creating an instance of my Courses class, iterating through it's prerequisites string array(after making sure it's not null so that I don't get a nullpointerexception). After that I wrote something like this for the html form:

for(int j=0; j<course.getCourse_pre().length; j++){
                    
                    out.println("<input type='checkbox' name='preqs' value='" + course.getCourse_pre()[j] + "'>" + course.getCourse_pre()[j] + "<br>");
                }

This iterates through the preqs string array of the instance of the course class and prints it out as checkboxes. After that you can get the parameter value like this in doPost:

String preqs[] = request.getParameterValues("preqs");

Should be pretty straightforward afterwards.

 

Edit: A problem I noticed with this is when I create a new class and add the preqs there, their coppies reappear on the new 'add course' screen. I'll see if I can fix that.

 

Edit2: My bad, I was retrieving the course preqs instead of course codes from the class instance. This should clean things up.

for (int i = 0; i < courses.size(); ++i) {

            Courses course = courses.get(i);
            out.println("<input type='checkbox' name='preqs' value='"
                    + course.getCourse_code() + "'>" + course.getCourse_code()
                    + "<br>");

        }

 

Hope it helps.

 

Last edited by kaancalstatela at 19:03 Jan 24, 2014.