Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Text only showing first word in field


Message #1 by mmarcus@n... on Wed, 21 Aug 2002 18:55:32
While learning quite a bit from Wrox - Beginning ASP Databases, I came 
upon a glitch either in code or my understanding of ASP.  In chapter 10 we 
are updating fields in an access database.  It all works fine until you 
call up a record that has more than one word in it.  In the update fields 
only the first record shows (even though all your words you update make it 
to the database).  This occurs in my input=text types.  I can get around 
this by using an TEXTAREA but it seems the input=text should work. My code 
(slightly changed from the book) for a test project is shown below.  Note 
that the code out of the book also exibits this trait.  Please help.  I am 
sure I am missing something simple.

Thanks:

Code:

<HTML>
<HEAD>
<TITLE>SQL To Modify Data Sales Reps- Update</TITLE>
</HEAD>
<BODY>
Update SRep Form Test 1<br><br>

<%
'***********************************************************
'* Step 1: Display a list of  Sales Rep names to select from
'***********************************************************
If Len(Request.Form("FormAction")) = 0 Then

	'Create the recordset object
	Set objRS = Server.CreateObject("ADODB.Recordset")

	'Open the recordset getting a list of all clubs
	objRS.Open "Select SRID, SRInitials, SRFirstName, SRLastName, 
SRAddress, SRCity, SRState, SRPhone, SRExtension, SRFax, SRCell, SREmail 
FROM tblSalesRep","dsn=CNDB"
%>
	<form action=UpdateSR.asp method=post name=frmDisplay>
		<input type=hidden name=FormAction value=Step2>
		<input type=hidden name=txtSRName>
		<table>
			<tr>
			<td colspan=2>Select a Sales Rep to update</td>
			</tr>
			<tr>
			<td>Sales Rep</td>
			<td><select name=cboSReps>
<%
			'Loop through the recordset adding each club to 
the combo box
			Do While Not objRS.EOF
%>
				<option value="<%=objRS("SRID")%>">
					<%=objRS("SRLastName")%></option>
<%
				objRS.MoveNext
			Loop

			'Close and dereference database objects
			objRS.Close
			Set objRS = Nothing
%>
				</select></td>
			</tr>
			<tr>
			<td height=60><input type=submit name=btnSubmit 
value=Submit></td>
			</tr>
		</table>
	</form>
	
	<script language=vbscript>
	Sub Window_OnLoad()
		'Save the Sales Rep currently displayed, just in case the
		'user wants to update this club
		frmDisplay.txtSRName.value = _
			frmDisplay.cboSReps
(frmDisplay.cboSReps.selectedIndex).text
	End Sub
	
	Sub cboSReps_OnClick()
		'Save the Sales Rep the user selects by clicking on the 
combo box
		frmDisplay.txtSRName.value = _
			frmDisplay.cboSReps
(frmDisplay.cboSReps.selectedIndex).text
	End Sub
	
	Sub cboSReps_OnChange()
		'Save the Sales Rep the user selects by scrolling the 
combo box
		'with the arrow keys
		frmDisplay.txtSRName.value = _
			frmDisplay.cboSReps
(frmDisplay.cboSReps.selectedIndex).text
	End Sub
	</script>
	
<%
'***********************************************************
'* Step 2: Display the form for editing a Sales Rep
'***********************************************************
ElseIf Request.Form("FormAction") = "Step2" Then

	'Create the recordset object
	Set objRS = Server.CreateObject("ADODB.Recordset")

	'Set the SQL string
	'strSQL = "Select * from tblSalesRep Where SRID = '" & _
		'Request.Form("cboSReps") & "'"

	strSQL = "Select * from tblSalesRep Where SRID = " & _
		Request.Form("cboSReps")& ";"
	
	'Open the recordset getting the SR details for this club
	objRS.Open strSQL,"dsn=CNDB"
%>
<form action=DisplaySRChanges.asp method=post name=frmUpdate>
	<input type=hidden name=Action value=Update>
	<input type=hidden name=txtSRID 
		value=<%=Request.Form("cboSReps")%>>
	<table>
		<tr>
		<td>Sales Rep</td>
		<td><font color=navy><%=Request.Form("txtSRName")%
></font></td>
		<td width=10></td>
		<td>SRID</td>
		<td><font color=navy><%=Request.Form("cboSReps")%
></font></td>
		</tr>
		<tr>
		<td nowrap>First Name</td>
		<td><input type=text name=txtSRFirstName size=10 
				value=<%=objRS("SRFirstName")%>></td>
		<td width=10></td>
		<td>Last Name</td>
		<td><input type=text name=txtSRLastName size=10
				value=<%=objRS("SRLastName")%>></td>	
	
		</tr>
		<tr>
		<td nowrap>Initials</td>
		<td><input type=text name=txtSRInitials size=10 
				value=<%=objRS("SRInitials")%>></td>
		<td width=10></td>
		<td>Address</td>
		<td><input type=text name=txtSRAddress size=10
				value=<%=objRS("SRAddress")%>></td>	
		</tr>
		<tr>
		<td nowrap>City</td>
		<td><input type=text name=txtSRCity size=10 
				value=<%=objRS("SRCity")%>></td>
		<td width=10></td>
		<td>State</td>
		<td><input type=text name=txtSRState size=10
				value=<%=objRS("SRState")%>></td>	
		</tr>		
		<tr>
		<td nowrap>Phone</td>
		<td><input type=text name=txtPhone size=10 
				value=<%=objRS("SRPhone")%>></td>
		<td width=10></td>
		<td>Extension</td>
		<td><input type=text name=txtSRExtension size=10
				value=<%=objRS("SRExtension")%>></td>	
		</tr>	
		<tr>
		<td nowrap>Fax</td>
		<td><input type=text name=txtSRFax size=10 
				value=<%=objRS("SRFax")%>></td>
		<td width=10></td>
		<td>Cell Phone</td>
		<td><input type=text name=txtSRCell size=10
				value=<%=objRS("SRCell")%>></td>	
		</tr>
<tr>
		<td>Address Full</td>
		<td colspan=4>
			<textarea rows=1 cols=30 name=txtSRAddress><%=objRS
("SRAddress")%>
			</textarea></td>
		</tr>			
		<tr>
		<td height=60><input type=submit name=btnSubmit 
value=Submit></td>
		</tr>
	</table>
</form>

<%
		'Close and dereference database objects
		objRS.Close
		Set objRS = Nothing

End If	'End If for step processing
%>

</BODY>
</HTML>
Message #2 by "Mike Marcus" <mmarcus@n...> on Wed, 21 Aug 2002 16:00:34 -0400
Found Answer in Archive (should have looked there first!)

This answer was by Walter "wb67" from November of 2001.

You need to put some quotes around the value attribute. Otherwise the
browser sees the space in customer name and assumes that the first word is
all there is.

Orignal - Returns only the first word:
		<td><input type=text name=txtSRAddress size=15
				value=<%=objRS("SRAddress")%>></td>
		</tr>
New: - Returns the entire stirng:
		<td><input type=text name=txtSRAddress size=15
				value="<%=objRS("SRAddress")%>"></td>
		</tr>

Thanks you all for this forum,

Mike

-----Original Message-----
From: mmarcus@n... [mailto:mmarcus@n...]
Sent: Wednesday, August 21, 2002 6:56 PM
To: Access ASP
Subject: [access_asp] Text only showing first word in field


While learning quite a bit from Wrox - Beginning ASP Databases, I came
upon a glitch either in code or my understanding of ASP.  In chapter 10 we
are updating fields in an access database.  It all works fine until you
call up a record that has more than one word in it.  In the update fields
only the first record shows (even though all your words you update make it
to the database).  This occurs in my input=text types.  I can get around
this by using an TEXTAREA but it seems the input=text should work. My code
(slightly changed from the book) for a test project is shown below.  Note
that the code out of the book also exibits this trait.  Please help.  I am
sure I am missing something simple.

Thanks:

Code:

<HTML>
<HEAD>
<TITLE>SQL To Modify Data Sales Reps- Update</TITLE>
</HEAD>
<BODY>
Update SRep Form Test 1<br><br>

<%
'***********************************************************
'* Step 1: Display a list of  Sales Rep names to select from
'***********************************************************
If Len(Request.Form("FormAction")) = 0 Then

	'Create the recordset object
	Set objRS = Server.CreateObject("ADODB.Recordset")

	'Open the recordset getting a list of all clubs
	objRS.Open "Select SRID, SRInitials, SRFirstName, SRLastName,
SRAddress, SRCity, SRState, SRPhone, SRExtension, SRFax, SRCell, SREmail
FROM tblSalesRep","dsn=CNDB"
%>
	<form action=UpdateSR.asp method=post name=frmDisplay>
		<input type=hidden name=FormAction value=Step2>
		<input type=hidden name=txtSRName>
		<table>
			<tr>
			<td colspan=2>Select a Sales Rep to update</td>
			</tr>
			<tr>
			<td>Sales Rep</td>
			<td><select name=cboSReps>
<%
			'Loop through the recordset adding each club to
the combo box
			Do While Not objRS.EOF
%>
				<option value="<%=objRS("SRID")%>">
					<%=objRS("SRLastName")%></option>
<%
				objRS.MoveNext
			Loop

			'Close and dereference database objects
			objRS.Close
			Set objRS = Nothing
%>
				</select></td>
			</tr>
			<tr>
			<td height=60><input type=submit name=btnSubmit
value=Submit></td>
			</tr>
		</table>
	</form>

	<script language=vbscript>
	Sub Window_OnLoad()
		'Save the Sales Rep currently displayed, just in case the
		'user wants to update this club
		frmDisplay.txtSRName.value = _
			frmDisplay.cboSReps
(frmDisplay.cboSReps.selectedIndex).text
	End Sub

	Sub cboSReps_OnClick()
		'Save the Sales Rep the user selects by clicking on the
combo box
		frmDisplay.txtSRName.value = _
			frmDisplay.cboSReps
(frmDisplay.cboSReps.selectedIndex).text
	End Sub

	Sub cboSReps_OnChange()
		'Save the Sales Rep the user selects by scrolling the
combo box
		'with the arrow keys
		frmDisplay.txtSRName.value = _
			frmDisplay.cboSReps
(frmDisplay.cboSReps.selectedIndex).text
	End Sub
	</script>

<%
'***********************************************************
'* Step 2: Display the form for editing a Sales Rep
'***********************************************************
ElseIf Request.Form("FormAction") = "Step2" Then

	'Create the recordset object
	Set objRS = Server.CreateObject("ADODB.Recordset")

	'Set the SQL string
	'strSQL = "Select * from tblSalesRep Where SRID = '" & _
		'Request.Form("cboSReps") & "'"

	strSQL = "Select * from tblSalesRep Where SRID = " & _
		Request.Form("cboSReps")& ";"

	'Open the recordset getting the SR details for this club
	objRS.Open strSQL,"dsn=CNDB"
%>
<form action=DisplaySRChanges.asp method=post name=frmUpdate>
	<input type=hidden name=Action value=Update>
	<input type=hidden name=txtSRID
		value=<%=Request.Form("cboSReps")%>>
	<table>
		<tr>
		<td>Sales Rep</td>
		<td><font color=navy><%=Request.Form("txtSRName")%
></font></td>
		<td width=10></td>
		<td>SRID</td>
		<td><font color=navy><%=Request.Form("cboSReps")%
></font></td>
		</tr>
		<tr>
		<td nowrap>First Name</td>
		<td><input type=text name=txtSRFirstName size=10
				value=<%=objRS("SRFirstName")%>></td>
		<td width=10></td>
		<td>Last Name</td>
		<td><input type=text name=txtSRLastName size=10
				value=<%=objRS("SRLastName")%>></td>

		</tr>
		<tr>
		<td nowrap>Initials</td>
		<td><input type=text name=txtSRInitials size=10
				value=<%=objRS("SRInitials")%>></td>
		<td width=10></td>
		<td>Address</td>
		<td><input type=text name=txtSRAddress size=10
				value=<%=objRS("SRAddress")%>></td>
		</tr>
		<tr>
		<td nowrap>City</td>
		<td><input type=text name=txtSRCity size=10
				value=<%=objRS("SRCity")%>></td>
		<td width=10></td>
		<td>State</td>
		<td><input type=text name=txtSRState size=10
				value=<%=objRS("SRState")%>></td>
		</tr>
		<tr>
		<td nowrap>Phone</td>
		<td><input type=text name=txtPhone size=10
				value=<%=objRS("SRPhone")%>></td>
		<td width=10></td>
		<td>Extension</td>
		<td><input type=text name=txtSRExtension size=10
				value=<%=objRS("SRExtension")%>></td>
		</tr>
		<tr>
		<td nowrap>Fax</td>
		<td><input type=text name=txtSRFax size=10
				value=<%=objRS("SRFax")%>></td>
		<td width=10></td>
		<td>Cell Phone</td>
		<td><input type=text name=txtSRCell size=10
				value=<%=objRS("SRCell")%>></td>
		</tr>
<tr>
		<td>Address Full</td>
		<td colspan=4>
			<textarea rows=1 cols=30 name=txtSRAddress><%=objRS
("SRAddress")%>
			</textarea></td>
		</tr>
		<tr>
		<td height=60><input type=submit name=btnSubmit
value=Submit></td>
		</tr>
	</table>
</form>

<%
		'Close and dereference database objects
		objRS.Close
		Set objRS = Nothing

End If	'End If for step processing
%>

</BODY>
</HTML>


  Return to Index