Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble Validating Form Field

Status
Not open for further replies.

Manch

Programmer
Jun 12, 2001
43
US
I have an ASP page with a form in it. The form contains two fields. The second field is a list box that gets its data from a database. This list box is generated dynamically using VBscript. This is why I chose an ASP page for this form as opposed to a HTML page, I did not know how to fill the list box on an HTML page.

The first field is simply a text box. I want to validate that the user did not leave it blank and I want to make sure it is a number.

I tried creating a simple sub routine on this same ASP page that checked the value of this field and was called from the Form's onsubmit action. I could not get this to work.

How can I validate this field and display a message to the user? I am open to changing this to a HTML page if the list box can still be filled. Here is my page:

Code:
<% @Language=VBScript%>
<HTML>
<HEAD>
<% 
	Dim objDB
	Dim objRS
	Dim sDBName
	Dim msg

	sDBName = &quot;driver={Microsoft Access Driver (*.mdb)};dbq=C:\Inetpub\[URL unfurl="true"]wwwroot\VoregWeb.mdb&quot;[/URL]
	Set objDB = Server.CreateObject(&quot;ADODB.Connection&quot;)
	objDB.Open sDBName

	Set objRS = objDB.Execute(&quot;select Distinct [StreetName] from [tblStreets] order by [StreetName]&quot;)	
%>
		
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>
<FORM  action=&quot;DetWard.asp&quot; method=POST id=form1 name=form1>
Street Number:
<Input Type=text name=&quot;Number&quot; size=8>
 
Street Name:
<% 
Response.Write(&quot;<select name=&quot;&quot;Address&quot;&quot;>&quot;)
Do While Not objRS.EOF
	Response.Write(&quot;<option value=&quot; & Chr(34) & objRS(&quot;StreetName&quot;) & Chr(34) & &quot;>&quot; & objRS(&quot;StreetName&quot;))
	objRS.MoveNext
Loop

Response.Write(&quot;</select>&quot;)%>
<Input Type=submit name=&quot;Submit&quot; Value=&quot;Submit Address&quot;>
</FORM>


<P> </P>

</BODY>
</HTML>

The values in the form are sent to another ASP page for processing.
 
Inside your loop to create the drop down box you could add another option box for example:
<%
Response.Write(&quot;<select name=&quot;&quot;Address&quot;&quot;>&quot;)
Do While Not objRS.EOF
response.write &quot;<option value=''>&quot;
Response.Write(&quot;<option value=&quot; & Chr(34) & objRS(&quot;StreetName&quot;) & Chr(34) & &quot;>&quot; & objRS(&quot;StreetName&quot;))
objRS.MoveNext
Loop

Response.Write(&quot;</select>&quot;)%>

then use javascript to check for a blank on that field
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top