|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Default Value in textbox not working like expected
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 Gazing into my crystal ball I observed "Drew"
<drew.laing@NOswvtc.dmhmrsas.virginia.SPMgov> writing in Show quote news:eiCqxwhFGHA.3324@TK2MSFTNGP12.phx.gbl: I would suggest not using response.write that way, just drop out of ASP and > 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 > > > 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 Drew wrote:
Show quote > 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. 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 Show quote "Paxton" <paxton***@hotmail.com> wrote in message news:1136924609.941127.113350@g43g2000cwa.googlegroups.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. > Thanks for the link, that looks like it will help a great deal in the
future! Thanks, Drew Show quote "Kyle Peterson" <kyle***@hotmail.com> wrote in message news:uxlzp$iFGHA.2896@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/code-wizards-reponse-write2.asp > > "Paxton" <paxton***@hotmail.com> wrote in message > news:1136924609.941127.113350@g43g2000cwa.googlegroups.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. >> > > 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 Show quote "Paxton" <paxton***@hotmail.com> wrote in message news:1136924609.941127.113350@g43g2000cwa.googlegroups.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. > |
|||||||||||||||||||||||