Title: RE: Checkbox Behavior

At the suggestion of another lister, I tested a checkbox again with an int field but had the same results - the field is not updated when the checkbox is checked->unchecked. (He is on Oracle - I'm on mySQL.) So I implemented my hack.

First I created a hidden input for each <db:checkbox > with the same name as the checkbox. I got the name by looking at the HTML source in the browser. (Like I said, it's a hack!) I also added the onClick below to the <db:checkbox >.

        <input name="f_1_0@root_15" type="hidden" id="f_1_0@root_15"/>
        <db:checkbox value="yes"  fieldName="street" >

Then I added the onLoad to the <body> and the following JavaScript. The

        <body bgcolor="#99CCFF" >
        <script language="JavaScript" type="text/JavaScript">

        // set all hidden fields associated with (same name) checkboxes
        function setHiddenAll() {

         for (i=0;i < document.forms.length;i++) {
          var myForm = document.forms[i];
          for (j=0;j < myForm.elements.length;j++) {
           var el = myForm.elements[j];
           if (el.type == "checkbox")
            setHidden(el);
          }
         }
        }


        // set hidden field associated with (same name) checkbox cb
        function setHidden(cb) {

         theForm = cb.form;
         for (i=0;i < theForm.elements.length;i++) {
          el = theForm.elements[i];
          if ((el.type == "hidden") && (el.name == cb.name) ) {
           if (cb.checked )
            el.value = "yes";
           else
            el.value = "no";
          }
         }
        }
        </script>
 
Now when the page loads, the value of the hidden input is updated with the checkbox value. If the checkbox is changed the hidden input changes too. This way there is always a value in the request associated with the checkbox name.

This works with TomCat 4.0.3. But obviously no guarantees ;-)

I assume someone who knows the dbForms source code (not me - yet) could implement something similar.

Regards
Dan

Reply via email to