• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with checkbox

 
Janice Guevara
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please I need some help...

Everytime I submit the value of a checkbox it gets "false" even though I check it.And even if the value was checked when the page loads and I submit the form the checkbox does not maintain its value.

I'm using the request.getParameterMap() method to see what the values of my form are.

I'm also using javascript to set the value of the checkbox but it doesn't work...here are the function and the html code:

function setCheckbox(checkbox,columnName){
alert(checkbox.getState());
if(checkbox.checked){
document.getElementsByName(columnName).value="true";

}
else{
document.getElementsByName(columnName).value="false";
}

}


<td>
<input type="checkbox" name="<%=pageColumns.getName()%>" checked onCclick="setCheckbox(this, modify_<%=pageColumns.getName()%>)" />
<input type="hidden" name="modify_<%=pageColumns.getName()%>" id="modify_<%=pageColumns.getName()%>" />
</td>

Thanks...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting more than single line of code, be sure to use UBB code tags in order to preserve its formatting.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a checkbox is checked, whatever is set as its value attribute will be sent on the request. When unchecked, no request parameter for the checkbox will be sent at all.

Be sure that your code accounts for this behavior.
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want your onclick event to set the value of the hidden field?
I presume you intentionally misspelled "onclick" to get past the forum limitations.

- you need quotes around the columnName so that it generates as a javascript string to pass to the function
 
Janice Guevara
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I get the checkbox value from the request.getParameterMap it is empty,it seems that it is not sent on the request...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!