Solved

dynamic check box  value

Posted on 2001-08-15
5
489 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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