Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display list

Status
Not open for further replies.

joyceda59

Technical User
Apr 3, 2007
29
CA
Hi

im creating this form where a bunch of servers are listed with checkboxes beside each.(the servers are pulled out of a sql tble). A user can any server. Once the user clicks the submit button, form validation occurs to see if any of the form fields is empty. If one of the fields is empty, then a message at the top of the screen will tell the user to complete the form. MY problem is to disply the server list and the servers that the user selected before submitting. Basically i want to take the servers that the user selected before sumitting, and display it. Here is my code:

Sub CheckServersChecked()

oConn.Open(ConnectionString)
sqlQuery1 = "SELECT serverName, serverLocation FROM tblInventoryServers WHERE (serverStateType = 'Locked' OR serverStateType = 'Controlled') AND (serverStatus = 'Online' OR serverStatus = 'Offline')"
Set oRs1 = oConn.Execute(sqlQuery1)

serverString = oRs1("serverName")

'serverSelect = Request("server")
strList = Request("server")
list = Replace(strList, "/", "")
list = Replace(list, " ", "")
serverArray =Split(list,",")


WHILE NOT oRs1.EOF
'if serverlist is not empty then add a ticked checkbox for each server
if strList <> "" Then
for x =0 to UBound(serverArray)

Response.Write serverArray(x)
selectCheckBox = "checked"
Response.Write "<br/>"
Next
Response.Write "<input type='checkbox' name='server' id='serverSelect' "& selectCheckBox &" value=" & serverString & "/>"
else
Response.Write oRs1("serverName")
Response.Write "<input type='checkbox' name='server' id='serverSelect' value=" & serverString & "/>"
Response.Write "<br/>"

end if

oRs1.MoveNext
WEND

oRs1.Close
oConn.Close

End Sub
 
While I know you have already solved your initial issue i do have a suggestion to make.
Right now you are looping through your recordset and then for each record looping through the selected servers from the previous page. You could easily speed this up a little with some string magic. Instead of looping through the array to determine if something was checked you could replace that with a single line InStr() statement that would give you the same result for lower cost, like so:
Code:
        strList = Request("server")
        list = Replace(strList, "/", "")
        [highlight]list = "#" & Replace(list, ", ", "#") & "#"[/highlight]
        
        WHILE NOT oRs1.EOF    
            [highlight]Response.Write oRs1("serverName")[/highlight]
            [highlight]Response.Write "<input type='checkbox' name='server' id='serverSelect' value=" & serverString[/highlight]
            [highlight]If InStr(list, "#" & oRs1("serverName") & "#") >= 0 Then Response.Write " checked"[/highlight]
            [highlight]Response.Write "/><br/>"[/highlight]
            
            oRs1.MoveNext
        WEND

Also, looking at the way your code is setup in the original example, I'm surprised your not getting repeats of every selected server for each record from the database. Basically it looks like each time you process a record from your recordset your code should be re-outputting all of the selected checkboxes. Even if you altered this to only occur once your going to have multiple checkboxes with the same value since you would be outputting them once from your array of selections and once from the recordset.

Anyways, just an afterthought,
-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top