Default Value in textbox not working like expected

Discussion in 'ASP General' started by Drew, Jan 10, 2006.

  1. Drew

    Drew Guest

    I am building an application for inserting and updating one field in a
    database. The database is in SQL Server and I am using Classic ASP. I have
    a dropdown listbox that is populated with names, when a name is selected it
    automatically submits the form and then replaces the dropdown listbox with
    the name of the resident selected. Now I need to take a field and split it
    into 2 textboxes. This is where my problems begin. The field is named
    ProblemO and looks something like this,

    ..150 This is a sample term

    I need to break this field up into Code and Term. Code being the .150 and
    the Term being "This is a sample term". I did this with the following code,

    Dim Problem
    Dim ProbCode
    Dim ProbTerm

    Problem = rsProblem0.Fields.Item("ProblemO").Value
    ProbCode = Left(Problem,4)
    ProbTerm = Trim(Right(Problem,(Len(Problem)-4)))

    If I Response.Write the above variables out, it is perfect, but if I try to
    make them default values for a textbox I am running into issues. The
    ProbCode works fine, but the ProbTerm cuts off at the first space. Below is
    my code,

    If rsProblem0.BOF And rsProblem0.EOF Then
    Response.Write("<input name=""ProblemCode"" type=""text""
    id=""ProblemCode"" size=""6""> - <input name=""ProblemTerm"" type=""text""
    id=""ProblemTerm"" size=""40"">")
    Else
    Response.Write("<input name=""ProblemCode"" type=""text""
    id=""ProblemCode"" value=" & ProbCode & " size=""6""> - <input
    name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=" & ProbTerm &
    "size=""40"">")
    End If

    How can I get this to work correctly?

    Thanks,
    Drew
     
    Drew, Jan 10, 2006
    #1
    1. Advertising

  2. Gazing into my crystal ball I observed "Drew"
    <> writing in
    news::

    > I am building an application for inserting and updating one field in a
    > database. The database is in SQL Server and I am using Classic ASP. I
    > have a dropdown listbox that is populated with names, when a name is
    > selected it automatically submits the form and then replaces the
    > dropdown listbox with the name of the resident selected. Now I need to
    > take a field and split it into 2 textboxes. This is where my problems
    > begin. The field is named ProblemO and looks something like this,
    >
    > .150 This is a sample term
    >
    > I need to break this field up into Code and Term. Code being the .150
    > and the Term being "This is a sample term". I did this with the
    > following code,
    >
    > Dim Problem
    > Dim ProbCode
    > Dim ProbTerm
    >
    > Problem = rsProblem0.Fields.Item("ProblemO").Value
    > ProbCode = Left(Problem,4)
    > ProbTerm = Trim(Right(Problem,(Len(Problem)-4)))
    >
    > If I Response.Write the above variables out, it is perfect, but if I
    > try to make them default values for a textbox I am running into issues.
    > The ProbCode works fine, but the ProbTerm cuts off at the first space.
    > Below is my code,
    >
    > If rsProblem0.BOF And rsProblem0.EOF Then
    > Response.Write("<input name=""ProblemCode"" type=""text""
    > id=""ProblemCode"" size=""6""> - <input name=""ProblemTerm""
    > type=""text"" id=""ProblemTerm"" size=""40"">")
    > Else
    > Response.Write("<input name=""ProblemCode"" type=""text""
    > id=""ProblemCode"" value=" & ProbCode & " size=""6""> - <input
    > name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=" &
    > ProbTerm & "size=""40"">")
    > End If
    >
    > How can I get this to work correctly?
    >
    > Thanks,
    > Drew
    >
    >
    >


    I would suggest not using response.write that way, just drop out of ASP and
    go straight into HTML, eg:

    <% 'get info from db
    'set variables
    Problem = rsProblem0.Fields.Item("ProblemO").Value
    ProbCode = Left(Problem,4)
    ProbTerm = Trim(Right(Problem,(Len(Problem)-4)))
    If rsProblem0.BOF And rsProblem0.EOF Then
    %>
    <input type="text" name="ProblemCode" id="ProblemCode" size="6"> <input
    type="text" name="ProblemTerm" type="text" id="ProblemTerm" size="40">
    <% else %>
    <input name="ProblemCode" type="text" id="ProblemCode" value="<%
    =ProbCode%>" size="6"> - <input name="ProblemTerm" type="text"
    id="ProblemTerm" value="<%=ProbTerm%>" size="40">
    <% end if%>

    IMHO, that's a lot easier to read/debug. Also, what happens when you view
    source? Perhaps there is a problem in the markup. Did you validate the
    markup the ASP is generating?

    --
    Adrienne Boswell
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
     
    Adrienne Boswell, Jan 10, 2006
    #2
    1. Advertising

  3. Drew

    Paxton Guest

    Drew wrote:
    > I am building an application for inserting and updating one field in a
    > database. The database is in SQL Server and I am using Classic ASP. I have
    > a dropdown listbox that is populated with names, when a name is selected it
    > automatically submits the form and then replaces the dropdown listbox with
    > the name of the resident selected. Now I need to take a field and split it
    > into 2 textboxes. This is where my problems begin. The field is named
    > ProblemO and looks something like this,
    >
    > .150 This is a sample term
    >
    > I need to break this field up into Code and Term. Code being the .150 and
    > the Term being "This is a sample term". I did this with the following code,
    >
    > Dim Problem
    > Dim ProbCode
    > Dim ProbTerm
    >
    > Problem = rsProblem0.Fields.Item("ProblemO").Value
    > ProbCode = Left(Problem,4)
    > ProbTerm = Trim(Right(Problem,(Len(Problem)-4)))
    >
    > If I Response.Write the above variables out, it is perfect, but if I try to
    > make them default values for a textbox I am running into issues. The
    > ProbCode works fine, but the ProbTerm cuts off at the first space. Below is
    > my code,
    >
    > If rsProblem0.BOF And rsProblem0.EOF Then
    > Response.Write("<input name=""ProblemCode"" type=""text""
    > id=""ProblemCode"" size=""6""> - <input name=""ProblemTerm"" type=""text""
    > id=""ProblemTerm"" size=""40"">")
    > Else
    > Response.Write("<input name=""ProblemCode"" type=""text""
    > id=""ProblemCode"" value=" & ProbCode & " size=""6""> - <input
    > name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=" & ProbTerm &
    > "size=""40"">")
    > End If
    >
    > How can I get this to work correctly?
    >
    > Thanks,
    > Drew


    .......
    Else
    Response.Write("<input name=""ProblemCode"" type=""text""
    id=""ProblemCode"" value=""" & ProbCode & """ size=""6""> - <input
    name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=""" &
    ProbTerm &
    """size=""40"">")

    You needed to add double quotes around the value. You only had one
    quote either side, which drops you out of the string literal, but none
    around the Values value.

    Adrienne's suggestion, while it has some merit in terms of readability,
    will chew up a hold load more CPU cycles on the server as the ASP dll
    is called everytime the parser encounters <% tags.

    /P.
     
    Paxton, Jan 10, 2006
    #3
  4. wizards like this may help you as well to turn text and html as well as asp
    variables into response.writes
    http://www.powerasp.com/content/new/code-wizards-reponse-write2.asp

    "Paxton" <> wrote in message
    news:...
    >
    > Drew wrote:
    >> I am building an application for inserting and updating one field in a
    >> database. The database is in SQL Server and I am using Classic ASP. I
    >> have
    >> a dropdown listbox that is populated with names, when a name is selected
    >> it
    >> automatically submits the form and then replaces the dropdown listbox
    >> with
    >> the name of the resident selected. Now I need to take a field and split
    >> it
    >> into 2 textboxes. This is where my problems begin. The field is named
    >> ProblemO and looks something like this,
    >>
    >> .150 This is a sample term
    >>
    >> I need to break this field up into Code and Term. Code being the .150
    >> and
    >> the Term being "This is a sample term". I did this with the following
    >> code,
    >>
    >> Dim Problem
    >> Dim ProbCode
    >> Dim ProbTerm
    >>
    >> Problem = rsProblem0.Fields.Item("ProblemO").Value
    >> ProbCode = Left(Problem,4)
    >> ProbTerm = Trim(Right(Problem,(Len(Problem)-4)))
    >>
    >> If I Response.Write the above variables out, it is perfect, but if I try
    >> to
    >> make them default values for a textbox I am running into issues. The
    >> ProbCode works fine, but the ProbTerm cuts off at the first space. Below
    >> is
    >> my code,
    >>
    >> If rsProblem0.BOF And rsProblem0.EOF Then
    >> Response.Write("<input name=""ProblemCode"" type=""text""
    >> id=""ProblemCode"" size=""6""> - <input name=""ProblemTerm""
    >> type=""text""
    >> id=""ProblemTerm"" size=""40"">")
    >> Else
    >> Response.Write("<input name=""ProblemCode"" type=""text""
    >> id=""ProblemCode"" value=" & ProbCode & " size=""6""> - <input
    >> name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=" & ProbTerm
    >> &
    >> "size=""40"">")
    >> End If
    >>
    >> How can I get this to work correctly?
    >>
    >> Thanks,
    >> Drew

    >
    > ......
    > Else
    > Response.Write("<input name=""ProblemCode"" type=""text""
    > id=""ProblemCode"" value=""" & ProbCode & """ size=""6""> - <input
    > name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=""" &
    > ProbTerm &
    > """size=""40"">")
    >
    > You needed to add double quotes around the value. You only had one
    > quote either side, which drops you out of the string literal, but none
    > around the Values value.
    >
    > Adrienne's suggestion, while it has some merit in terms of readability,
    > will chew up a hold load more CPU cycles on the server as the ASP dll
    > is called everytime the parser encounters <% tags.
    >
    > /P.
    >
     
    Kyle Peterson, Jan 10, 2006
    #4
  5. Drew

    Drew Guest

    Thanks for the link, that looks like it will help a great deal in the
    future!

    Thanks,
    Drew

    "Kyle Peterson" <> wrote in message
    news:uxlzp$...
    > wizards like this may help you as well to turn text and html as well as
    > asp variables into response.writes
    > http://www.powerasp.com/content/new/code-wizards-reponse-write2.asp
    >
    > "Paxton" <> wrote in message
    > news:...
    >>
    >> Drew wrote:
    >>> I am building an application for inserting and updating one field in a
    >>> database. The database is in SQL Server and I am using Classic ASP. I
    >>> have
    >>> a dropdown listbox that is populated with names, when a name is selected
    >>> it
    >>> automatically submits the form and then replaces the dropdown listbox
    >>> with
    >>> the name of the resident selected. Now I need to take a field and split
    >>> it
    >>> into 2 textboxes. This is where my problems begin. The field is named
    >>> ProblemO and looks something like this,
    >>>
    >>> .150 This is a sample term
    >>>
    >>> I need to break this field up into Code and Term. Code being the .150
    >>> and
    >>> the Term being "This is a sample term". I did this with the following
    >>> code,
    >>>
    >>> Dim Problem
    >>> Dim ProbCode
    >>> Dim ProbTerm
    >>>
    >>> Problem = rsProblem0.Fields.Item("ProblemO").Value
    >>> ProbCode = Left(Problem,4)
    >>> ProbTerm = Trim(Right(Problem,(Len(Problem)-4)))
    >>>
    >>> If I Response.Write the above variables out, it is perfect, but if I try
    >>> to
    >>> make them default values for a textbox I am running into issues. The
    >>> ProbCode works fine, but the ProbTerm cuts off at the first space.
    >>> Below is
    >>> my code,
    >>>
    >>> If rsProblem0.BOF And rsProblem0.EOF Then
    >>> Response.Write("<input name=""ProblemCode"" type=""text""
    >>> id=""ProblemCode"" size=""6""> - <input name=""ProblemTerm""
    >>> type=""text""
    >>> id=""ProblemTerm"" size=""40"">")
    >>> Else
    >>> Response.Write("<input name=""ProblemCode"" type=""text""
    >>> id=""ProblemCode"" value=" & ProbCode & " size=""6""> - <input
    >>> name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=" & ProbTerm
    >>> &
    >>> "size=""40"">")
    >>> End If
    >>>
    >>> How can I get this to work correctly?
    >>>
    >>> Thanks,
    >>> Drew

    >>
    >> ......
    >> Else
    >> Response.Write("<input name=""ProblemCode"" type=""text""
    >> id=""ProblemCode"" value=""" & ProbCode & """ size=""6""> - <input
    >> name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=""" &
    >> ProbTerm &
    >> """size=""40"">")
    >>
    >> You needed to add double quotes around the value. You only had one
    >> quote either side, which drops you out of the string literal, but none
    >> around the Values value.
    >>
    >> Adrienne's suggestion, while it has some merit in terms of readability,
    >> will chew up a hold load more CPU cycles on the server as the ASP dll
    >> is called everytime the parser encounters <% tags.
    >>
    >> /P.
    >>

    >
    >
     
    Drew, Jan 11, 2006
    #5
  6. Drew

    Drew Guest

    Thanks, that is what happened... Here is the code that was screwing up,

    Response.Write("<input name=""ProblemCode"" type=""text"" id=""ProblemCode""
    value=" & ProbCode & " size=""6""> - <input name=""ProblemTerm""
    type=""text"" id=""ProblemTerm"" value=" & ProbTerm & " size=""40"">")

    Here is the code that is fixed,

    Response.Write("<input name=""ProblemCode"" type=""text"" id=""ProblemCode""
    value=""" & ProbCode & """ size=""6""> - <input name=""ProblemTerm""
    type=""text"" id=""ProblemTerm"" value=""" & ProbTerm & """ size=""40"">")

    If you will notice, there was only 1 quote around ProbCode and there needed
    to be 3... Thanks!

    Thanks,
    Drew

    "Paxton" <> wrote in message
    news:...
    >
    > Drew wrote:
    >> I am building an application for inserting and updating one field in a
    >> database. The database is in SQL Server and I am using Classic ASP. I
    >> have
    >> a dropdown listbox that is populated with names, when a name is selected
    >> it
    >> automatically submits the form and then replaces the dropdown listbox
    >> with
    >> the name of the resident selected. Now I need to take a field and split
    >> it
    >> into 2 textboxes. This is where my problems begin. The field is named
    >> ProblemO and looks something like this,
    >>
    >> .150 This is a sample term
    >>
    >> I need to break this field up into Code and Term. Code being the .150
    >> and
    >> the Term being "This is a sample term". I did this with the following
    >> code,
    >>
    >> Dim Problem
    >> Dim ProbCode
    >> Dim ProbTerm
    >>
    >> Problem = rsProblem0.Fields.Item("ProblemO").Value
    >> ProbCode = Left(Problem,4)
    >> ProbTerm = Trim(Right(Problem,(Len(Problem)-4)))
    >>
    >> If I Response.Write the above variables out, it is perfect, but if I try
    >> to
    >> make them default values for a textbox I am running into issues. The
    >> ProbCode works fine, but the ProbTerm cuts off at the first space. Below
    >> is
    >> my code,
    >>
    >> If rsProblem0.BOF And rsProblem0.EOF Then
    >> Response.Write("<input name=""ProblemCode"" type=""text""
    >> id=""ProblemCode"" size=""6""> - <input name=""ProblemTerm""
    >> type=""text""
    >> id=""ProblemTerm"" size=""40"">")
    >> Else
    >> Response.Write("<input name=""ProblemCode"" type=""text""
    >> id=""ProblemCode"" value=" & ProbCode & " size=""6""> - <input
    >> name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=" & ProbTerm
    >> &
    >> "size=""40"">")
    >> End If
    >>
    >> How can I get this to work correctly?
    >>
    >> Thanks,
    >> Drew

    >
    > ......
    > Else
    > Response.Write("<input name=""ProblemCode"" type=""text""
    > id=""ProblemCode"" value=""" & ProbCode & """ size=""6""> - <input
    > name=""ProblemTerm"" type=""text"" id=""ProblemTerm"" value=""" &
    > ProbTerm &
    > """size=""40"">")
    >
    > You needed to add double quotes around the value. You only had one
    > quote either side, which drops you out of the string literal, but none
    > around the Values value.
    >
    > Adrienne's suggestion, while it has some merit in terms of readability,
    > will chew up a hold load more CPU cycles on the server as the ASP dll
    > is called everytime the parser encounters <% tags.
    >
    > /P.
    >
     
    Drew, Jan 11, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Huff
    Replies:
    2
    Views:
    421
    Richard Huff
    Jan 6, 2004
  2. Patrick Kowalzick
    Replies:
    5
    Views:
    511
    Patrick Kowalzick
    Mar 14, 2006
  3. Jurjen de Groot
    Replies:
    0
    Views:
    335
    Jurjen de Groot
    May 19, 2008
  4. Randell_D
    Replies:
    1
    Views:
    83
    Doug Gunnoe
    Dec 26, 2007
  5. Stevo
    Replies:
    13
    Views:
    238
    Bart Van der Donck
    Apr 2, 2009
Loading...

Share This Page