What is wrong I want the form and the form validation in the same page

K

karenmiddleol

I have a simple form to accept two form fields and display the values
entered on pressing the submit button. The following is the form I have
created to accept the two entries and display the form fields on
pressing the submit form. It does not work can somebody please correct
the code or provide a simple equivalent code where I can have the form
and the validation and usage of the form values in the same ASP page.

Thanks
Karen

<html>
From Period : <input type="text" name="FromPeriod">
<br>
To Period : <input type="text" name="ToPeriod">
<input type="submit" value="Submit" action = "Go">
</form>

<%
Dim FromVal, ToVal
FromVal = Request.Form("FromPeriod")
ToVal = Request.Form("ToPeriod")
Response.Write FromVal
Response.Write ToVal


If FromVal & ToVal <> ""
Then
Response.Write "Valid data entered"
End If
%>
</body>
</html>
 
E

Evertjan.

wrote on 30 sep 2005 in microsoft.public.inetserver.asp.general:
I have a simple form to accept two form fields and display the values
entered on pressing the submit button. The following is the form I have
created to accept the two entries and display the form fields on
pressing the submit form. It does not work can somebody please correct
the code or provide a simple equivalent code where I can have the form
and the validation and usage of the form values in the same ASP page.

Thanks
Karen

<html>

<br>
To Period : <input type="text" name="ToPeriod">
<input type="submit" value="Submit" action = "Go">

Why action = "Go" ? Has no meaning, imho.
</form>

<%
Dim FromVal, ToVal
FromVal = Request.Form("FromPeriod")
ToVal = Request.Form("ToPeriod")
Response.Write FromVal

Response.Write FromVal & said:
Response.Write ToVal

Response.Write ToVal & said:
If FromVal & ToVal <> ""
Then

The Then must be on the same line as the If
Response.Write "Valid data entered"
End If
%>
</body>
</html>

with the Then corrected it works fine here,
except that

FromVal & ToVal <> ""

is true when "one of them is non empty.

I think you mean:

If (FromVal <> "") AND (ToVal <> "") Then
 
S

Steven Burn

'// Begin pForm.asp
<html>
<body>
<form method="post" action="pForm.asp">
From Period : <input type="text" name="FromPeriod"><br>
To Period : <input type="text" name="ToPeriod">
<input type="submit" value="Submit" action = "Go">
</form>
<%
'// Check the first field only (assumes it is required)
If Request.Form("FromPeriod") <> "" Then
Response.Write "From: " & Request.Form("FromPeriod") & "<br>"
Response.Write "To: " & Request.Form("ToPeriod")
End If
%>
</body>
</html>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
M

McKirahan

I have a simple form to accept two form fields and display the values
entered on pressing the submit button. The following is the form I have
created to accept the two entries and display the form fields on
pressing the submit form. It does not work can somebody please correct
the code or provide a simple equivalent code where I can have the form
and the validation and usage of the form values in the same ASP page.

Thanks
Karen

[snip]

http://www.aspfaq.com/5003 !
 
M

Martin Walke

HI Karen,

I don't think you can do what you want this way. You're trying to validate
data with server side scripting, which is run *before* the page is sent to
the browser. You need to use client side scripting (js or vb) to validate.

HTH
Martin
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top