Skip to Content
0
May 21, 2009 at 09:19 AM

How to capture checkbox values dynamically

54 Views

Hi Experts,

In my html page I have a requirement to generate the check boxes dynamically and capture those values after page submission.

Here is the code to generate the check boxes dynamically.

<%
  data : i(1) type N .
  data : checkname(10).

  i = 1.
  loop at ty_agr_tcodes into st_agr_tcodes.
       Concatenate 'usr' i into checkname. "" inside the loop checkname will be assigned as usr1, usr2 on i increment, and this checkname will be assinged to check box name.
        move st_agr_tcodes-tcode to t_tcode.
        read table t_desc into wa_desc with key tcode = t_tcode.

%>
<tr class="td">
  <td class="coltcode"><%= st_agr_tcodes-tcode%></td>
    <td class="coldesc"><%= wa_desc-TTEXT%></td>
    <td class="coluser"><input name="<%=checkname%>" value==""id="<%=checkname%>"  type="checkbox" checked="checked"/></td>
    <td class="colhod"><input name="ho_All" id="hod1" type="checkbox"/></td>
    <td class="colctm last"><input name="ct_All" id="ctm1" type="checkbox"/></td>
</tr>
<%
 i = i + 1.
endloop.
%>

Here is the code to capture the checkbox values (which is not working)

<%
CASE event_id.
   WHEN 'submit'.
         i = request->get_form_field('recCount').  *"number of checkboxes generated with names "usr1,usr2...."*
         cnt = i.
         DO cnt TIMES.
             Concatenate 'usr' i into checkname1.  *" checkname1 is assigned with usr1,usr2 etc.*
             request->get_form_field(checkname).  " *In general checkname contains usr1, usr2 which are checkbox names. but I am getting compile error here, saying can't use variable to get the form values. My porblem will be solved if i can find a way to capture the values of usr1, usr2..............n.*
             i = i - 1.
         ENDDO.
%>

Can any one suggest how to achieve this to get the check box values dynamically.

Thanks,

Chinna.