Breaking my head: value from a checkbox
Jul 26, 2010

I've been breaking my head trying to get a value out of a checkbox for validation, i.e. before submission to the server. For a variety of other fields, I can get it via the client call like:

var cName = document.getElementById("#{id:checkBox1}").value;
if(cName == "" || cName == null) {
    alert("Please check a box. ");
    return false; 
But this just isn't working. I'm not getting any value at all. Here is my checkbox: 

    <xp:checkBox text="This document does not have an original date"
        id="checkBox1" value="#{viewScope.dateEscape}" defaultChecked="false"
        <xp:this.checkedValue><![CDATA["No date"]]></xp:this.checkedValue>
        <xp:eventHandler event="onclick" submit="true" refreshMode="complete">


 I just can't seem to get a value from the client side with the code above. I've been doing variations on full and partial refresh,  but to no avail. I've also tried putting the value into a viewScope, or not. In my mind, this is something that should act like Input Validation in classic Notes development.


In the process I'm working on, the checkbox will be in a custom control that is asking for a date, and if there is no date for the user to check the box, so there is  no question as to the intent. I don't want to save the doc at this point, as there is another custom control that will let them upload a file and save it. But with the workflow, I want to get the date/no date nailed down first. I'm usingHide/Whens err Visible to  make a simple wizard like interface. So I want to see if I have a value in either the date field or this checkbox before going to the next step. I posted on contingent validation, but the code that where there doesn't seem to work and I can't figure out why. If anyone has any suggestions, please tell me, otherwise we'll have to be calling the king's horses and the king's men.




Add a Comment 
More Actions 
Comments (3)

1 Mark Hughes commented July 26 2010 Permalink Recommendations 0
try getting the checked value as in


should be true or false

2 Howard Greenberg commented July 26 2010 Permalink Recommendations 0
You have to loop through the array that holds all your values and see if the checked property is true. If it is, than use the .value property for that element of the array to get the value. This code from this website will work:

3 Brian M Moore commented July 27 2010 Permalink Recommendations 0
@Mark - Thanks! That did it. I appreciate it. I'm pushing into JavaScript via XPages, and JS is understandably different from what I'm used to in LotusScript, it's taking me a bit to wrap my head around it all.


@Howard - thanks too! I'm doing a single box, but I know I'll be needing to get into returned arrays, so I've pulled your suggestion over as well.
This is an archive of my previous blog attachments are in the download control