473,378 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Default Value in textbox not working like expected

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
Jan 10 '06 #1
5 3233
Gazing into my crystal ball I observed "Drew"
<dr********@NOswvtc.dmhmrsas.virginia.SPMgov> writing in
news:ei**************@TK2MSFTNGP12.phx.gbl:
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
Jan 10 '06 #2

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.

Jan 10 '06 #3
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/...nse-write2.asp

"Paxton" <pa*******@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...

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.

Jan 10 '06 #4
Thanks for the link, that looks like it will help a great deal in the
future!

Thanks,
Drew

"Kyle Peterson" <ky*****@hotmail.com> wrote in message
news:ux**************@TK2MSFTNGP10.phx.gbl...
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/...nse-write2.asp

"Paxton" <pa*******@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...

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.


Jan 11 '06 #5
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" <pa*******@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...

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.

Jan 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ian D | last post by:
Firstly apologies for the convoluted question. I found this problem whilst building a larger database. I've distilled it down to as small as possible and can send a 200k example to anyone who has...
38
by: MLH | last post by:
I have 2 global constants declared in the same global module: Global Const MY_VERSION$ = "1.04" Global Const ProjectName$ = "MyProj" I have 2 global procedures designed to return the value of...
10
by: Jane Sharpe | last post by:
Hi, I have a textbox with the words "Enter your name here" inserted as default text - At the moment, to remove this the user must highlight all the text and delete before they type in their name...
1
by: Jon S via DotNetMonster.com | last post by:
HI all, I'm returning a dataset to a gridview control. When the gridview asp.net control is populated from the returning dataset some of the cells remain empty. This is expected as some data...
12
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST>
10
by: Brad Baker | last post by:
I have an asp.net/csharp application that requires a particular variable to work properly. This variable is usually passed via a query string in the URL when the application is first run but under...
3
by: MLH | last post by:
I have a table named tblDoItems. It has a text field named . There is no default value property setting at the table level. I have a query named qryAdminDoList based solely on the table that looks...
1
by: EJO | last post by:
I've looked around the groups and don't have tried some of the various suggestions to no avail. So I'm hoping someone can help me out here. I have a form that, when a cmd button is clicked,...
5
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls In a ASP.Net form I have 20 textboxes and 20 dropdownlists(ddl). All ddl(s) are databound and get...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.