Search code examples
htmlasp-classic

How to create a sub function with html code?


I'm trying to create a sub function in classic asp that shows Password: the text space ? Any suggestions?

Sub GetPassword()
   response.write " Password:"
   <input type="text" name="txtEmPwd" size="20" value="<%=strEmPwd%>">&nbsp;&nbsp;1st 3 chars of 
   last name&nbsp;<input type="text" name="txtFirst3" size="5" maxlength=3 value="<%=strFirst3%>"> 
end sub

I get an error where the greater than character

Microsoft VBScript compilation error '800a0400'

Expected statement


Solution

  • That's because you are writing html directly in server side code. You have to add the html as a string, something like this:

    Sub GetPassword()
       dim html
       html = "Password:"
       html = html & "<input type='text' name='txtEmPwd' size='20' value='" & strEmPwd & "'>&nbsp;&nbsp;1st 3 chars of last name&nbsp;"
       html = html & "<input type='text' name='txtFirst3' size='5' maxlength='3' value='" & strFirst3 & "'>"
       Response.Write html
    end sub