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:

Microsoft Office 365 Servers and Random Errors Issue Microsoft Office 365 Servers and Random Errors Issue
Posted by November 14, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Sending/Resending Emails Using a MIME File with MAILTOOL Sending/Resending Emails Using a MIME File with MAILTOOL
Posted by November 8, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Sending an HTML Email on Your IBM i Using MAILTOOL Sending an HTML Email on Your IBM i Using MAILTOOL
Posted by November 1, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Transferring License Keys from One System to Another Transferring License Keys from One System to Another
Posted by October 31, 2022
BVSTools >> BVSTools Software Discussion
Calculating the Size of a File Before Base64 Encoding Calculating the Size of a File Before Base64 Encoding
Posted by August 13, 2022
Programming >> RPG Programming
GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File
Posted by August 11, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts
Posted by August 6, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions
Posted by July 26, 2022
BVSTools >> BVSTools Software Discussion >> GreenTools for Microsoft Apps (G4MS) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives
Posted by July 19, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives
Posted by July 15, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page
Posted by July 4, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System? What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System?
Posted by June 27, 2022
BVSTools >> BVSTools Software Discussion
GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page
Posted by May 3, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
How Do I Switch From MAILTOOL Plus to GreenTools for Google (OAuth 2.0) or Microsoft Office 365? How Do I Switch From MAILTOOL Plus to GreenTools for Google (OAuth 2.0) or Microsoft Office 365?
Posted by April 18, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
PTFs Issued for SSL/TLS Issues PTFs Issued for SSL/TLS Issues
Posted by March 12, 2022
IBM Power Systems >> PTF Watch

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).