Solved

dynamic check box  value

Posted on 2001-08-15
5
488 Views
Last Modified: 2006-11-17
i would like to get the value of the checkbox which is created dynamically depends upon the no of datas in sql server. how to write code in asp??

0
Comment
Question by:venki001
5 Comments
 

Expert Comment

by:meganhall
ID: 6387672
'MH - when writ eout the check boxes to the form use this:
Do until rs.Eof
%>
  <input type="checkbox" name="chkPeople<%=rs("ID")%>" value="<%=rs("ID")%>">
 <%  
  rs.MovenNext
Loop





For each item in Request.Form'MH - only checked checkboxes are posted
 
  If Left(item,9) = "chkPeople" Then
    'MH - know the chechboxes has been posted
    'MH - get the ID
    intID = Request.Form(item)
  End If
 
Next

Hope this helps :-)
Cheers
0
 
LVL 2

Expert Comment

by:MCM
ID: 6388196
Megan's code is on the right track, but i think it will barf a little; the variable -item- will contain, not the name of the input submitted, but the value. try this variation (i haven't tested it so it may need some prodding):

'Here we draw the form:
<FORM name="SOMETHING" action="processingPage.asp">
<%
Do until rs.Eof
%>
 <input type="HIDDEN" name="IDMARKER<%=rs("ID")%>" value="IDMARKER<%=rs("ID")%>">
 <input type="checkbox" name="chkPeople<%=rs("ID")%>" value="<%=rs("ID")%>">
<%  
 rs.MovenNext
Loop
%>
</FORM>


---
and in processingPage.asp,

<%
For each item in Request.Form
 If Left(item,9) = "IDMARKER" Then
   'MH - know the chechboxes has been posted
   'MH - get the ID
   intID = mid(item, 9)
   if request.form("chkPeople" & intID)="on" then
       'your box was checked, so do some stuff
   end if
 End If
Next
%>
0
 
LVL 7

Accepted Solution

by:
John844 earned 50 total points
ID: 6389339
or just name all of the check boxes the same thing with different values

on the next page you can just use request("chkPeople") to get the comma delimited string of checked items or just index into the collection of items.

here is a very simple example:

<%@ Language=VBScript %>
<%
dim i
if request("chkTest") <> "" then
  for i = 1 to request("chkTest").count
    Response.Write "val of " & i & " = " & request("chkTest")(i) & "<BR>"
  next
end if


if request("chkTest2") <> "" then
  Response.Write "Values of checked checkboxes<BR>"
  for i = 1 to request("chkTest2").count
    Response.Write request("chkTest2")(i) & " prize : " & request(request("chkTest2")(i)) & "$<BR>"
  next
end if
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<form>
<input type=checkbox name=chkTest value=chk1>
<input type=checkbox name=chkTest value=chk2 checked>
<input type=checkbox name=chkTest value=chk3 checked>
<input type=checkbox name=chkTest value=chk4>


p1<input type=checkbox name=chkTest2 value=p1><br>
<input type=hidden name=p1 value="100">
p2<input type=checkbox name=chkTest2 value=p2 checked><br>
<input type=hidden name=p2 value="200">
p3<input type=checkbox name=chkTest2 value=p3 checked><br>
<input type=hidden name=p3 value="300">
p4<input type=checkbox name=chkTest2 value=p4><br>
<input type=hidden name=p4 value="400">

<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</form>

</BODY>
</HTML>
0
 
LVL 2

Expert Comment

by:MCM
ID: 6391216
john's is better than mine; i thought that checkboxes always returned "on" but tha'ts just their default behaviour when you don't specify a value. silly me.

megan's works too if you modify it thusly:

'MH - when writ eout the check boxes to the form use this:
Do until rs.Eof
%>
 <input type="checkbox" name="chkPeople<%=rs("ID")%>" value="chkPeople<%=rs("ID")%>">
<%  
rs.MovenNext
Loop

For each item in Request.Form'MH - only checked checkboxes are posted
 
 If Left(item,9) = "chkPeople" Then
   'MH - know the chechboxes has been posted
   'MH - get the ID
   intID = mid(item,10)
 End If
 
Next
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6722059
I am sorry to see that Asker has not returned to update and finalize this question.  I am, therefore, force accepting this question.  In the event the Asker returns with additional needs related to this question, please respond and continue the collaboration process.
 
If there are questions in this regard, please comment and I'll return when I can.
 
The HELP DESK link on the left is informative, and includes this site's Guidelines and Member Agreement as well as assistance related to Questions and Answers.  Here is the QA link, as a reference.
 
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
 
Thank you,
Moondancer
Community Support Moderator @ Experts Exchange
 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now