Classic asp not recognizing space character

1.6k Views Asked by At

Really this is a 2 question post but I'll sum it up..

  • I can't get the white space to recognize within the option of a select statement.

CSS: select{font-family: monospace;}

Here's my code: (imagine i'm writing the select out first).. this is the options

                for i = 0 to db-1
                response.write "<option"
                if i = 0 then
                    response.write " selected"
                end if
                response.write " value='"
                if db(i,3) = 1 and session("id") <> db(i,4) then
                    Response.Write "-1"
                else
                    Response.Write db(i,0)
                end if
                Response.Write "'> "
                'Option Text, add ID
                dim optionText
                optionText = "(" & db(i,0) & ")"                                            
                'Make all Id's width equal so the text begins on the same vertical line
                'Pad with spaces before text, padding for up to id = 99999
                if len(optionText) < 7 then
                    Do While len(optionText)<7
                        optionText = optionText & "REPLACE HERE" 
                    Loop
                end if
                'Option Text, add Detail
                optionText = optionText + Trim(db(i,5))
                'Text
                if len(optionText) > 84 then
                    Response.write left(optionText,81) & "..."          
                else
                    'Pad Text to same length so all "locked" can be padded to the right
                    if len(optionText) < 84 then
                    Do While len(optionText)<84
                        optionText = optionText & "REPLACE HERE" 
                    Loop
                    end if  
                    Response.Write optionText                           
                end if                    
                'Locked
                Response.write " &#x1f512; admin &#x1f512;" 
            next

replacing the "REPLACE HERE" in 2 places above with &nbsp; or &#160; or just a " " had no affect, the page only always respects the first space.

Here in the image you will see the accurate padding lined out.

  • 7 - ( id )
  • 84 - total text length up until the "lock" symbol

enter image description here

1

There are 1 best solutions below

0
Flakes On BEST ANSWER

The do while loop is not doing what you are expecting; once you do optionText = optionText & "&nbsp;", the length of optionText goes above 7, and exits the loop. What you need to do is add 7-len(optionText) spaces to the string.

You could use a for loop to do that:

if len(optionText) < 7 then
    for i=1 to 7-len(optionText)
        optionText = optionText & "&nbsp;" 
    next
end if