Default Value in textbox not working like expected

D

Drew

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
 
A

Adrienne Boswell

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?
 
P

Paxton

Drew said:
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.
 
D

Drew

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

Thanks,
Drew
 
D

Drew

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top