|
-
Apr 19th, 2004, 04:22 AM
#1
Thread Starter
KING BODWAD XXI
ASP: ITS NAFF Please help (Resolved)
How can i get an array of checkboxes to work
i have a database with client sites. Now these are dynamic and can change meaning i need to create checkboxes at runtime. So far i can find no way of making a working array of checkboxes
Code:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<form method = post action = "test1.asp">
<input type = 'checkbox' name= 'Site'> Site 1
<input type = 'checkbox' name = 'Site'> Site 2
<input type = 'submit' name = 'Go' Value = 'Enter'>
</form>
<%
dim Returns
dim arrays()
dim I
Returns = Request.Form ("Site")
if Returns <> "" then
I = 0
Arrays = split(Returns, ",")
upper = ubound(arrays)
Do until I = upper
Response.write I & ": " & Arrays(I) & "<br>"
I = I + 1
loop
end if
%>
</BODY>
</HTML>
this is my first try.
The problem i have is that if the box isnt checked nothing is returned in the form object. Any that are checked are in no order that can help me establish which boxes they are?
Hope that makes sense. But my head is swimming with the absolute rubbish that is ASP.
Last edited by BodwadUK; Apr 22nd, 2004 at 02:02 AM.
-
Apr 21st, 2004, 11:29 AM
#2
Fanatic Member
Why not name your checkboxes differently. That way you can get the names of the controls that are submitting the data. Try the following:
This code will generate your checkboxes.
Code:
<%
dim no_of_sites: no_of_sites = 3
dim site_counter: site_counter = 0
%>
<form method=post action="receiver.asp" >
<%
for site_counter = 1 to no_of_sites
%>
<input type=checkbox name=chk<%=site_counter%>><label for=chk<%=site_counter%>>site <%=site_counter%></label>
<%
next
%>
<br>
<input type=submit value=submit>
</form>
Then this will tell you which ones have submitted data and what the data is:
Code:
<%
dim no_of_inputs: no_of_inputs = Request.Form.Count
dim input_counter: input_counter = 0
for input_counter = 1 to no_of_inputs
%>
Item <%=Request.Form.Key(input_counter)%> = <%=Request.Form.Item(input_counter)%><br>
<%
next
%>
Hope that helps.
-
Apr 22nd, 2004, 02:01 AM
#3
Thread Starter
KING BODWAD XXI
Ok ill take a look
Thankyou
-
Apr 22nd, 2004, 02:56 AM
#4
Code:
<form method = post action = "test1.asp">
<input type = 'checkbox' name= 'Site' value='1'> Site 1
<input type = 'checkbox' name = 'Site' value='2'> Site 2
<input type = 'submit' name = 'Go' Value = 'Enter'>
</form>
The value attribute is the data submitted when the checkbox is checked. You can use the value attribute to identify which checkboxs have been checked.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|