Click to See Complete Forum and Search --> : checkbox issue


Rxyz
11-08-2006, 04:58 PM
checkbox checked value is not sent on form submission.

<input type="checkbox" name="split" value="true" onclick="enableName();" id="splitID"/>


do I have to give

value="true". I tried with and without it too. still on server side I am not getting split value as true. it is false always. I checked the request params split is not there in it.

what am i missing?? why is the checked value not sent to server??

thanks.

grumpyoldtechs
11-08-2006, 05:06 PM
could you post your serverside script? as thats most likely the problem

Rxyz
11-08-2006, 05:15 PM
thanks for your response.

actually I am using struts.
here is the code

struts-config

The below form-bean is session scoped and hence using reset.

<form-bean name="CustForm" type="com.formbeans.CustForm" dynamic="true">
...........
<form-property name="split" type="java.lang.Boolean"/>


</form-bean>



public class CustForm extends DynaValidatorForm {

public CustForm() {
}

public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {

set("split", Boolean.FALSE);
}

}


DispatchCustAction

public ActionForward save(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException
{
DynaValidatorForm frm = (DynaValidatorForm)form;

..............
...............

return mapping.findForward("successSave");
}



JSP:
<html:form>
.............
<html:checkbox name="CustForm" property="split"/>

...
</html:form>


When this jsp is first loaded the checkbox above is unchecked.

When user checked the checkbox, and clicked a submit save button, in the save method of dispatch action I was expecting to see the split value as "true". But it was "false" when I debug.

why is this?

grumpyoldtechs
11-08-2006, 05:20 PM
ah your using jsp this is where i get lost lol.

i reckon you will get faster response in the serverside forums

ray326
11-08-2006, 09:19 PM
Could be your Javascript. This works as you expect, i.e. sends mycb=true when checked.

<input type="checkbox" name="mycb" value="true">

When name and id are used together they should have the same value unless you have something like a radio button array.

You may be using a new version of Struts but my experience is that the form elements need to all be typed as String and a set of "shadow" objects of the desired types be declared in the ActionForm and used by the Java side.

I highly recommend the Struts Recipes book published by Manning.