Link to home
Start Free TrialLog in
Avatar of 4running
4running

asked on

request.form with a local variable?

Basically, I have a first page which goes through a dbase, and if the email field holds data, it outputs it along with a checkbox next to it.  The name of the checkbox is the email address which is outputted.  

Is there an easy way to make a submit button that will take only the checked addresses and send them to a mail client?

Right now, i have a second page which again checks the fields for data, and puts them into an array.  I have been trying to find a way to use Request.Form("x") where x is a local variable to the second page, which would match up to the first page's data.  Here's some code, I think I even managed to confuse myself with my ramblings.

1st Page:
rs.MoveFirst
counter = 0

while not rs.eof
counter = counter + 1
email = rs("Primary_Email")
lea = rs("LEA Name")
If email <> "" Then
Response.Write "<input type='checkbox' name="
Response.Write email
Response.Write">"
emails(counter) = email
Response.Write emails(counter)
Response.Write "<br>"
End If
  rs.MoveNext
Wend

2nd Page:
rs.MoveFirst
counter = 0

Response.Write "<a href='mailto:"
while not rs.eof
counter = counter + 1
email = rs("Primary_Email")
lea = rs("LEA Name")

If email <> "" Then

emails(counter) = email

End If

'This is where I'm trying to fix
If Request.Form([email]) = "on" Then

sendTo(counter) = email
End If
Response.Write sendTo(counter)
Response.Write ", "
rs.MoveNext
Wend

Response.Write "'>"
Response.Write "Submit</a>"



any ideas?
Avatar of gladxml
gladxml

4running,

Is there an easy way to make a submit button that will take only the checked addresses and send them to a mail client?

There is...

First you need to make your check the same name and only the value that will vary depending on your db.

The name of the checkbox is the email address which is outputted.  

assuming your recordset object is

<input type="checkbox" name="chkbox" value="<%=rs("ID")%>">


your asp code would be

     For i = 1 to Request("chkbox").Count
          emailadd = Request("chkbox")(i)
          repsonse.write emailadd
     Next

HTH...

Happy programming...



4running,

TO make it more clearer...

assuming your recordset object is rs and you email fieldname email then

<input type="checkbox" name="chkbox" value="<%=rs("email")%>">


your asp code would be

    For i = 1 to Request("chkbox").Count
         emailadd = Request("chkbox")(i)
         repsonse.write emailadd
    Next

HTH...

Happy programming...
4running,

Below is the revise code...

1st page
<%
rs.MoveFirst
while not rs.eof%>
<input type="checkbox" name="chkbox" value="<%=rs("Primary_Email")%>">
<%
 rs.MoveNext
Wend
%>



2nd page
<%
For i = 1 to Request("chkbox").Count
        emailadd = Request("chkbox")(i)
        str = str & email
Next
%>
<a href="mailto:<%=str%>">Submit</a>

HTH...

HAppy programming...
ASKER CERTIFIED SOLUTION
Avatar of gladxml
gladxml

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 4running

ASKER

Thanks gladxml, you the bomb!
4running,

Glad to be of help...

Regards,
Glad
Hi 4running,

if its possible can you post the full sections of the code here as I'm doing something similar but instead of emailing them, i delete their records from the db.

I have no idea where the code for the 2nd page can be used in my program, hope you can post a reference for me.

Thanks!
I'm able to delete if only 1 checkbox is clicked.

If i were to click more than 1 checkbox, nothing happens.

<%
dim con
dim sql

sql = "DELETE * FROM logintable WHERE name LIKE '" + Request("delete") + "'"

set con = Server.CreateObject("ADODB.Connection")
con.Open "test77","",""

'For loop is to loop through if there are more than 1 checkbox ticked, but it is not working yet
For i =1 to Request("delete").Count
con.execute(sql)
Next
%>

I can't put the (i) beside the Request("delete") as it will generate an error.

Does anyone know what to add to delete from more than 1 checkbox?

Help appreciated.
FYPJ,

OK try this sql...

Why not open a new question...


      strSQL = "DELETE FROM logintable WHERE name = '"
      For i = 1 to Request("delete").Count
            itemname = Request("delete")(i))
            con.execute sql & itemname & "'"
      Next


Regards,
gladxml
<%
str=""
For i = 1 to Request("chkbox").Count
      emailadd = Request("chkbox")(i)
      str = str & emailadd
Next
%>
<a href="mailto:<%=str%>">Submit</a>
 
Hi again, I have some questions on this thread again.

As my query is concerning this question and I am starving for points, I will not open a new question.

<a href="mailto:<%=str%>">Submit</a>

the variable str here stores the list of addresses that were ticked by the user.

How can the mail actually be send if there are no "," inbetween each address?

Or is there something I'm missing here?

I'm working on something similar but i put the list of address into a textfield before sending the mail and the list of addresses are like "abc@jj.com123@hotmail.comsam@yahoo.com".

How can i concatenate a "," for each address looped in here?
I have sovled the above problem. Thanks anyway.