How to display the entire field value in the text box, where the field has spaces?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Indrajit Chakraborty
    New Member
    • Aug 2010
    • 1

    How to display the entire field value in the text box, where the field has spaces?

    I am developing a simple web site in ASP. I have a web page which has a form, and I want to set the values of two text box to 2 fields selected by a query. One of the fields is a name field which has the First Name and the Last Name separated by a space. The text box only shows the First Name and not the last Name. Any idea how to show the complete field value?
    Code:
    <%
    Response.Expires = 0
    Response.Cookies ("name")= ""
    Response.Cookies ("Eid")= ""
    Dim a,b,c,e,f,con,strQx,rs,strUrl,connectionString,nm,eid
    
    a = Request.Form("t1")
    b = Request.Form("t2")
    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\My Team\TM Testing\Team Details4.mdb;"
    
    Set con = Server.CreateObject("ADODB.Connection")
    con.Open connectionString
    Set rs = Server.CreateObject("ADODB.Recordset")
    strQx = "SELECT Users.NAME, Users.[EMP ID] FROM Users WHERE UserID='"&a&"' AND Password='"&b&"' " 
    rs.Open strQx,con, adOpenForwardOnly, adLockOptimistic
    
    
    If rs.EOF Then
    	rs.close
    	Set rs = Nothing
    	con.close
    	Set con = Nothing
    	strUrl = "http://localhost/index.htm"
    	strUrl = strUrl & "?Error"	
    	Response.Redirect strUrl
    End If	
    
    c = rs("Name")
    e = rs("EMP ID")
    
    %>
    <html>
    
    <head>
    <title>Online Tracker System</title>
    </head>
    
    <body onload=setfoc()>
    
    <h1><font face="Calibri" size="6" color="#99FFCC"><b><img border="0" src="image3061.gif" width="377" height="114">Online
    Tracker System&nbsp;&nbsp;&nbsp;&nbsp; </b></font><img border="0" src="image315.gif"></h1>
    
    <form method="POST" name="f1" action="upload.asp">
    	<p align="left"><font face="Arial Rounded MT Bold"><font size="2">Week:</font> <select size="1" name="D1" tabindex="1">
        <option>WK1</option>
        <option>WK2</option>
        <option>WK3</option>
        <option>WK4</option>
        <option>WK5</option>
      </select>&nbsp;&nbsp;&nbsp; <font size="2">Date :</font> <input type="text" name="T1" size="17" onclick="OpenWin()" readonly tabindex="2">
      <font size="2">Name:</font> <input type="text" name="T2" value=<%=rs("Name")%> size="37" readonly style="position: relative">
    </form>
    
    
    <script language ="JavaScript">
    <!--
    function setfoc()
    {
    	document.f1.D1.focus();
    }
    -->
    </script>
    </body>
    </html>
  • azrar
    New Member
    • Nov 2008
    • 11

    #2
    The problem is that you did not put quotation marks around the value attribute of the input.

    Code:
    <input type="text" name="T2" value="<%=rs("Name")%>" size="37" readonly style="position: relative">
    Suggestion: use the local variable you created "c" instead of the recordset object.

    Code:
    <input type="text" name="T2" value="<%=c%>" size="37" readonly style="position: relative">

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      Azrar is right, but I think it is valid to use the recordset object there as he does in his first example. Think about this: the recordset object is already there, why bother having IIS create another variable to hold another value you already have a handle on?

      In the future, a lot of these types of mistakes become really obvious when you look at the HTML code, this would have appeared like this in the HTML:
      Code:
      <input type="text" name="T2" value=Indrajit Chakraborty size="37" readonly style="position: relative">
      Looking at it this way, it is pretty obvious what Azrar is saying.

      Jared
      Last edited by jhardman; Aug 25 '10, 04:02 AM. Reason: took out some redundancy

      Comment

      • azrar
        New Member
        • Nov 2008
        • 11

        #4
        Thanks for your reply Jared.

        There are several reasons I suggested using a local variable instead of the recordset object:

        1. he had already created local variable "c" in his code ( c = rs("Name") )

        2. local variables are much lighter than recordset objects (less overhead). Accessing the value of a local variable is much faster than accessing the data in an object. If you need to access that data more than once in the script, it starts making a difference.

        Comment

        Working...