Results 1 to 4 of 4

Thread: ASP: ITS NAFF Please help (Resolved)

  1. #1

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Unhappy 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.
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  2. #2
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    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.

  3. #3

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    Ok ill take a look


    Thankyou
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width