• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problems with checkbox

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said.
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic