Solved

dynamic check box  value

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP - problem with MS SQL Select Query? 10 60
Pass through dll 2 91
Html fieldset fix its height and width 4 30
Load data upon clicking a button 8 34
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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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