bvstone

Reading Multiple Checkboxes on a Web Page with the eRPG SDK

Posted:

Reading Multiple Checkboxes on a Web Page with the eRPG SDK

Recently I was asked how I perform a specific task with the eRPG SDK.

Suppose you have a table with each row being a row of data.  There is also a checkbox for each row which will tell your application to update/delete this specific row.  

You want to know:

  • Which checkbox is checked
  • Which record that checkbox relates to

One of my personal applications that I use to keep track of licensing for our software has just such an application.  Here is how we do it in a very simplified version:

The Template

First, the detail template line (which will be written out for each record) looks like the following:

/$list1
    <tr>
      <td">
        <input type="checkbox" name="/%detrrn%/del" value="y" title="Delete" onChange="updateRow('/%detrrn%/change');">
        <input type="hidden" name="/%detrrn%/change" id="/%detrrn%/change" value="n">
        <input type="hidden" name="detrrn" value="/%detrrn%/">
      </td>
....
    </tr>

You will see a replacement value of /%detrrn%/ on this record in a few places.  This will be replaced with the Relative Record Number (RRN) of the record we are reading from our Customer Key file.  Adding the RRN as a prefix on the field names is what will allow us to have unique form field names for each record of our file.  We also have a hidden field named detrrn that is written out only in this first cell, just so the RRN itself will be available to our application.

Displaying the Table

When writing out this information using the eRPG SDK to a web page, the program looks like this:

FCSTKEY1   IF   E           K DISK    INFDS(DETDS)      
 ****************************************************************  
 * Prototypes                                                   *  
 ****************************************************************  
 /COPY QCOPYSRC,P.ERPGSDK                                          
 /COPY QCOPYSRC,P.STRING                                           
 ****************************************************************  
D DETDS           DS                          
D  DetRRN               397    400I 0         
...
 /free
   #loadSection('list1');      
   SETLL CMEMAIL CSTKEY1;      
   READE CMEMAIL CSTKEY1;      
                               
   dow (not %eof(CSTKEY1));   
     #replaceData('/%detrrn%/':%editc(DetRRN:'Z')) 
...
     READE CMEMAIL CSTKEY1;      
   enddo;

This was done quite a few years ago, so the %editc() could be replaced with %char() if you wanted.  But, once we are done we will have a table row that looks like this:

    <tr>
      <td>
        <input type="checkbox" name="10364del" value="y" title="Delete" onChange="updateRow('10364change');">
        <input type="hidden" name="10364change" id="10364change" value="n">
        <input type="hidden" name="detrrn" value="10374">
      </td>
...
    </tr>

A sample of the actual table is as follows:

Now, we are using an onChange action in our application.  The JavaScript for the updateRow() function looks like the following:

function updateRow(row) {
  document.getElementById(row).value="y";
}

Again, this was done a few years ago (before jQuery) so this could also easily be updated if needed.  But, we see that all this does is update the hidden field of 10364change to the value of "y",  What this does is in our processing program (the program that runs when the form is submitted) allows us to know if a specific row has changed.  In the real application, more than just this checkbox can initiate a change (such as an updated serial number or model number), but for this example, we will stick to just using the checkbox.

The next step is reading the data into our program and finding which rows have changed.  This is done using the following:

...
D i               S             10i 0     
D detrrn          S             10i 0   
D detRRNx         S             32  
...  
 /free
  i = 1;                                                  
  detRRN = #CtoN(#getData('detrrn':i));                   
                                                          
  dow (detRRN > 0);                                       
    detRRNx = %editc(detRRN:'Z');                         
                                                          
    if (#getData(%trim(detRRNx) + 'change') = 'y');       
      CHAIN detRRN CSTKEYPF;                              
                                                          
      if (%found(CSTKEYPF));                              
                                                          
        if (#getData(%trim(detRRNx) + 'del') = 'y');      
          exsr $DelCal; 
          DELETE RCSTKEY;  
...         
    i = (i + 1);                             
    detRRN = #CtoN(#getData('detrrn':i));                             
  enddo;

The #CtoN() function is something I wrote many years ago to convert characters to numeric.  It is included with the eRPG SDK as well.  These days we can use %dec(), but I've found I like using #CtoN() even so because if the data is invalid, instead of using a MONITOR block and issuing an error, it will just return zero, which, in most cases lets me know that there is an error.

To start, we set the index variable of i to 1.   This will be used as an index to retrieve the specific instance of the detrrn variable.  Because each row of our table has a detrrn variable, we will retrieve a list of them like this:

detrrn=10374&detrrn=10375&detrrn=10376...

For each RRN we retrieve, we use the value of that field to retrieve the values for the uniquely named fields in our form.  That means that on our first iteration this code:

#getData(%trim(detRRNx) + 'change')

Will really be doing this:

#getData('10375change')

We can then use this method to retrieve any form fields from our page, each of them uniquely prefixed with this specific row id.

Now, the one issue one could have with using the RRN as a unique ID is if someone does a Reorganization on the file between the time the page is displayed and the update is performed.  This of course will throw off the RRN.  And if this will be an issue, I would recommend some other way of uniquely identifying each record in the file (such as your own RRN as a field in the file that is unique).  Or better yet, don't reorg while your web applications are running.  ;)

But, for me, using the actual RRN of the record works just fine.

There are some updates that could be done with this, but it's "not broke" so I'll save "fixing" it for sometime when I have more free time.  :)


Last edited 04/13/2017 at 09:19:47



Latest Posts:

MAILTOOL Updated to Allow G4GSMAIL as Option in Routers File MAILTOOL Updated to Allow G4GSMAIL as Option in Routers File
Posted by June 28, 2020
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
BVSTools Now Offers Interface with Infor's ION APIs BVSTools Now Offers Interface with Infor's ION APIs
Posted by May 15, 2020
BVSTools >> BVSTools Announcements
More V7R4 IFS File CCSID Issues and The Fix More V7R4 IFS File CCSID Issues and The Fix
Posted by March 4, 2020
IBM Power Systems >> (QGPL) IBM i
Error Retrieving IP Address by Name Error Retrieving IP Address by Name
Posted by February 25, 2020
BVSTools >> BVSTools Software Discussion
Logging jobs that hit an outq Logging jobs that hit an outq
Posted by February 13, 2020
Programming >> CL Programming
GreenTools for Google Apps (G4G) v12.60 Released with Shared Drive Features and More... GreenTools for Google Apps (G4G) v12.60 Released with Shared Drive Features and More...
Posted by February 4, 2020
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Allowing Requests over Port 80 For SSL Validation (ie, Namecheap, etc) Allowing Requests over Port 80 For SSL Validation (ie, Namecheap, etc)
Posted by January 31, 2020
Programming >> Web Programming
GreenTools for Slack (G4SLK) v3.00 Released GreenTools for Slack (G4SLK) v3.00 Released
Posted by January 17, 2020
BVSTools >> BVSTools Announcements >> GreenTools for Slack (G4SLK) Specific Announcements
Calling a QSH Command from RPG Calling a QSH Command from RPG
Posted by December 26, 2019
Programming >> RPG Programming
SPLTOOL Print Range (PRTRNG) Function Updated to Handle Spooled Files up to 999,999,999 Pages SPLTOOL Print Range (PRTRNG) Function Updated to Handle Spooled Files up to 999,999,999 Pages
Posted by December 14, 2019
BVSTools >> BVSTools Announcements >> Spooled File Tools (SPLTOOL) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Updated to v6.00 - Now Uses Microsoft Graph APIs GreenTools for Microsoft Apps (G4MS) Updated to v6.00 - Now Uses Microsoft Graph APIs
Posted by November 24, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
V7R4 Changes CCSID of Compressed File Using PASE JAR Command - Here's The Fix V7R4 Changes CCSID of Compressed File Using PASE JAR Command - Here's The Fix
Posted by November 21, 2019
IBM Power Systems >> (QGPL) IBM i
Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens
Posted by November 11, 2019
BVSTools >> BVSTools Software Discussion >> Get URI (GETURI) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality
Posted by October 20, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
BVSTools is Now Running V7R4M0 BVSTools is Now Running V7R4M0
Posted by September 28, 2019
BVSTools >> BVSTools Announcements

Reply




Copyright 1983-2020 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).