Extracting checkbox stuff jQuery

jdpjamesp

ProgressTalk.com Moderator
Staff member
The web gurus at work are off at the moment and I'm struggling a bit. I've built a series of checkboxes dynamically and on a click event of a button I want to establish which ones have been checked and which not to pop in hidden fields (in a different form) for passing through Ajax to Progress code for processing. I either need a comma delimited list of ID/Checked pairs, or 2 delimited lists, one of the IDs and one of the checked statuses. I'm using jQuery for this, but struggling. Anyone got any pointers to help?

Here's my HTML (sorry about the lack of formatting!):

Code:
<p id="ProfileDetailsGroup"> </p>
<p>
<label class="DialogLabel" for="Create11323126">CPG Profile Desc</label>
<input id="Create11323126" class="ui-widget-content ui-corner-all CreateProfileCheckbox" type="checkbox" name="11323126">
</p>
<p>
<label class="DialogLabel" for="Create11318633">CRB1 Yield</label>
<input id="Create11318633" class="ui-widget-content ui-corner-all CreateProfileCheckbox" type="checkbox" name="11318633">
</p>
<p>
<label class="DialogLabel" for="Create11318644">CRB1 Carbon score</label>
<input id="Create11318644" class="ui-widget-content ui-corner-all CreateProfileCheckbox" type="checkbox" name="11318644">
</p>
 
Code:
  /* checkbox */
  IF get-value("c1") NE "on" THEN
    {&OUT} 'c1:<INPUT TYPE="checkbox" name="c1">' SKIP.
  ELSE
    {&OUT} 'c1:<INPUT checked TYPE="checkbox" name="c1">' SKIP.

  {&OUT} get-value("c1") SKIP.
 
Thanks - I've managed to solve this just now.

Code:
var $MyCheckboxes = $j(":checkbox");
                  var $MyCheckboxesLength = $j(":checkbox").length;
                  var $CommaOrNot = "";
                  var $ProfileDetailIDs = "";
                  var $ProfileDetailChecked = "";
                  for (cb=0;cb<$MyCheckboxesLength;cb++) {
                      if($MyCheckboxes[cb].id.indexOf("AmendProfileGroup") == -1)
                          continue;
                      $ProfileDetailIDs = $ProfileDetailIDs + $CommaOrNot + $MyCheckboxes[cb].name;
                      $ProfileDetailChecked = $ProfileDetailChecked + $CommaOrNot + $MyCheckboxes[cb].checked;
                      $CommaOrNot = ",";
                  }
                  $j("#AmendProfileDetails").val($ProfileDetailIDs);
                  $j("#AmendProfileDetailsChecked").val($ProfileDetailChecked);
 
Back
Top