From client to server validation

A

alec

Hello,
Below please find a very simple code: form (form1) checks if two fields (T1
and T2) have entries and then submits to another page (confirmation.asp) As
you can see validation is done on the client side.
How do I change this code below so that validation be done on the server side?
Since I am a new to JavaScript programming, could you please do all the
changes necessary.
Thank you.


<html>
<head>
<script>
function DoSubmit()
{
if (document.form1.T1.value=="")
{
window.alert("Please fill the field No. 1 ")
return false
}
if (document.form1.T2.value=="")
{
window.alert("Please fill the field No. 2")
return false
}
document.form1.target="_self"
document.form1.action="confirmation.asp"
document.form1.submit()
}



</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Submit</title>
</head>

<body>

<form method="POST" action="--WEBBOT-SELF--" name="form1">
<!--webbot bot="SaveResults" U-File="_private/form_results.csv"
S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><input type="text" name="T1" size="20"></p>
<p><input type="text" name="T2" size="20"></p>
<p> </p>
<span style="cursor:hand" onclick="DoSubmit()">Submit</span>
</form>

</body>
</html>
 
M

MD Websunlimited

Hi Alec,

You'd have to change the type of page to ASP then there are two possible methods for doing the validation. For example.

<%
dim t1, t2, errMsg

errMsg = ""

t1 = request.form("T!")
if len(t1) = 0 then
errMsg = "Please enter a value for T1<br>"
end if
t2 = request.form("T2")
if len(t2) = 0 then
errMsg = errMsg = "Please enter a value for T2<br>"
end if

if len(errMsg) = 0 then
response.redirect "nextpage.asp"
end if

<html>

....

<body>
<% if len(errMsg) > 0 then response.write errMsg %>
......

<form action="thispage.asp" ..... >
.....
</form>
 

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

Top