SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing htmltable cells

    Hi,

    I'm facing a problem with accessing values from htmltable which i generate based on files from one of directories in my web application. Here's code I use to generate table

    Code:
    	Function GenerateAttachTable
    	
    		Dim fso, folder, files, NewsFile,sFolder  
    		Set fso = CreateObject("Scripting.FileSystemObject")  
    		sFolder = "Attachments"
    
    		Set folder = fso.GetFolder(Server.MapPath(sFolder))  
    		Set files = folder.Files    
    		Response.Write("<table style='border: 1px solid black; border-collapse: collapse;' id='attach' name='attach'>")
    		Response.Write("<tr><th>FileName</th><th>Attach</th></tr>")
    		Dim index
    		index = 0
    		
    		For each folderIdx In files    
    			Response.Write("<tr>")
    				Response.Write("<td>" & folderIdx.Name & "</td>") 
    				Response.Write("<td style='text-align: center;'><input type=checkbox id='chk[" & index & "]' name='chk[" & index  & "]' /></td>")
    				index   = index  + 1
    			Response.Write("</tr>")
    		Next  
    		Response.Write("</table>")
    	
    	end function
    I do not know how to check which checkboxes were checked. I tried something like Request.Form("attach") and then loop through this object but i do not get any results.

    Thanks for any advice!

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Are you meaning check which boxes were checked AFTER the form is submitted? (i.e. you run the above code to generate the HTML, the user checks some boxes and submits, THEN you want to check?) If yes then your HTML is missing <form></form> tags, so you don't actually have a form that can be submitted.

    Or are you meaning check which boxes have been PREVIOUSLY checked and make those checkboxes automatically ticked in the generated HTML?
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I call my function inside html <Form> and my Form declaration looks like this
    <form id="frmMain" name="frmMain" action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="post">

    I want to get values after submit and i do not know how to get access to generated table and loop through it rows/cells.

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to learn how to find if a checkbox is selected, google the following words and you will get examples:

    "request.form checkbox is checked"

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    "I want to get values after submit"
    Code:
    cb0 = Request.Form("chk[0]")
    cb1 = Request.Form("chk[1]")
    If you're not certain how many checkboxes there might be, you could add a hidden field to the GenerateAttachTable function and pass that along with the form ...
    Code:
    		Response.Write("</table>")
    		Response.Write("<input type='hidden' name='index' value='" & (index-1) & "' />")
    Then you could put the checkboxes in an array sized by the index ...
    Code:
    index = Request.Form("index")
    Redim cbArr(index)
    For i = 0 to index
      tmp = Request.Form("chk[" & index & "]")
      If Len(tmp) > 0 Then
        cbArr(i) = "On"
      Else
        cbArr(i) = "Off"
      End If
    Next
    By the way ... GenerateAttachTable looks a lot more like a Sub than it does a Function.
    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

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