Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

dynamic check box  value

Posted on 2001-08-15
5
Medium Priority
?
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 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