cancel
Showing results for 
Search instead for 
Did you mean: 

How to capture checkbox values dynamically

chinna_babu2
Active Participant
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

raja_thangamani
Active Contributor
0 Kudos

Look at the below link. Same issue discussed and resolved.

[Dynamic checkbox|]

Raja

Answers (2)

Answers (2)

chinna_babu2
Active Participant
0 Kudos

.

RieSe
Contributor
0 Kudos

Hi,

very simple



* Local declarations.
  DATA:
    field               TYPE LINE OF tihttpnvp,
    fields              TYPE         tihttpnvp,
    grouping_item       TYPE LINE OF   phtmlb_selectablelinkbaritems,
    characteristic_value
                        TYPE          /euh/mms_bapi_char_value,
    parameter_value     TYPE           xuvalue.
  FIELD-SYMBOLS:
   <characteristic_value_gr>
                        TYPE          /euh/mms_grouped_char.

  request->get_form_fields( CHANGING fields = fields ).

[

Doing this in oninputprocessing you cann capture all formfields.

Regrads,

Stefan