Solved

dynamic check box  value

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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 video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

14 Experts available now in Live!

Get 1:1 Help Now