Forums

Retrieve Chronoforms Data for Update

hcharris 26 Nov, 2013
Background: I have a form that is made up of 86 checkboxes. No Group; just individual fields. I want to be able to create a record for a given location and then update that record as needed. The problem is unchecking records. I couldn't uncheck and get it to save on an update.

I approached the problem with two javascripts. One is called from an onClick in each field and it updates the field with a "T" or "F" according to whether or not the checkbox is checked:

function toggleCk(chkBox)
    {
        if (chkBox.checked)
        {
          chkBox.value = "T";
          chkBox.checked = true;
        }
        else
        {
          chkBox.value = "F";
          chkBox.checked = false;
        }
    alert (chkBox.value);
    } 


This seems to be working correctly. The second script, is using code I found here to create an onload event:

window.addEvent('load', function() {

   var checkboxs = document.getElementsByClassName("radio");

   alert(checkboxs.length);

   for (var i = 0; i <= checkboxs.length - 1; i++) 

   {
          alert(checkboxs[i].name);
          alert(checkboxs[i].value);

       if(checkboxs[i].value=="T")
       {
          checkboxs[i].value = "T";
          checkboxs[i].checked = true;

       }
       else
       {
           checkboxs[i].value="F";
       }
    }
});


I have the following actions in the onLoad event:

Session to Data (passing the county)
DB Record Loader
Load JS (the second javascript that executes when the form is loaded)
Load JS (the first javascript that executes from the onClick event in each element)
Show HTML


Here is a snippet of two of the checkbox fields:

<!-- the LWG offers all practices -->
<tr>
	<td colspan="6">
		<div class="form_item">
			<div class="form_element cf_checkbox">
				<input title="" class="radio" id="pn_all" name="pn_all" type="checkbox" onClick="toggleCk(this)" value="" /><strong>
				The LWG offers all practices listed.</strong><br /><br /><strong>The LWG offers only the practices checked below:</strong>
			</div>
		</div><div class="cfclear"> </div>
	</td>
</tr>
<!-- Cell 1A -->
<tr>
	<td style="vertical-align:text-top">
	    <div class="form_item">
		    <div class="form_element cf_checkbox">
		        <div class="float_left">
					<input title="" class="radio" id="pn_472" name="pn_472" type="checkbox" onClick="toggleCk(this)" />
				</div>
			</div>
		</div>
	</td>
	<td>Access Control (Ft)</td>
	<td>472</td>
<!-- Cell 1B -->


I have checked the database and a "T" is being saved when the checkbox is checked and the first javascript is called to set the value. I have also looked at the code in Firebug and the onClick script is correctly setting the value.

The problem is that when the record is retrieved the "T" is not shown therefore is not set correctly when the form is rendered. I'm thinking I'm not retrieving the fields correctly for onLoad loop that sets the values in the form. The first alert shows the name attribute but I am assuming that the value attribute has not been loaded. When does Chronforms load the values from the database?

Suggestions would be greatly appreciated.
hcharris 27 Nov, 2013
sloanthrasher,

Thank you for your reply. Obviously I was not aware of ghosting. Once implemented, the page worked as expected. I was making this much harder than it needed to be.

Thanks again, Carter.
This topic is locked and no more replies can be posted.