How to get the name of checkbox control in ASP

Dear sir

I need to get the name of the checkbox control I did created in ASP page using

For i = 1 to counter
Dim chk
chk = "C" & i ' the name of the check box
   x2=x2 &" <input id=chk  name=chk" & " type=checkbox" & "value=No"
    x2=x2&" > "
next
The name is change using this code but :

I need a code help me to get the name of the control which change in run time and use the value of it for email purpose.



if request("B5")="send" then


For i = 1 to counter
Dim chk
chk = "C" & i ' the name of the check box
if chk.value=true then

DIM MYMAIL
SET MYMAIL=SERVER.CreateObject ("CDO.message")
MYMAIL.From = "abdallah@dpg-kwt.com"
MYMAIL.To ="abdallah@dpg-kwt.com"

MYMAIL.Subject="Ticket no : " 
MYMAIL.TextBody= "Your ticket has been finish by web host"'
MYMAIL.Send

next

or any controls to store the address of email come from database in it to use it by sending operation.

or find the controls name with thier value to do any code job.



Best regards;
Abdallah Kurdi
abdallah1973Asked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
Essentially a checkbox is either on or off. If it is off then it is not posted back to the page. So, you can tell which checkboxes were checked using something like:

    <%
        For i = 1 To counter
            If Not IsEmpty(Request.Form("chk" & i)) Then
               '// The checkbox was checked
            End If
        Next
    %>
0
 
hujiCommented:
I think you should use this:

<%
FOR i = 1 TO counter
  chk = "C" & i ' the name of the check box
  IF Request(chk)<>"" THEN
    DIM MYMAIL
    SET MYMAIL=SERVER.CreateObject ("CDO.message")
    MYMAIL.From = "abdallah@dpg-kwt.com"
    MYMAIL.To ="abdallah@dpg-kwt.com"
    MYMAIL.Subject="Ticket no : " 
    MYMAIL.TextBody= "Your ticket has been finish by web host"'
    MYMAIL.Send
  END IF
NEXT
%>

This also fixes a typo in carl_tawn's code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.