Javascript to Validate Asp Forms
I have developed a website and have included a form for new members to register. The website is coded in such a way that the Form is generated in ASP. This means that when I insert the JavaScript to validate the ASP form it won't work. Does anyone know how to validate it using Javascript without having to recreate the page so that the form isnt generated using ASP.
The ASP code is shown below:
<%
Content = "" 'Clear the Content string
QStr = Request.QueryString("login") 'Save the login querystring to QStr
if ucase(left(QStr,6))="CREATE" then
Title = "Registration"
else
Title = "Login"
end if
'The code below saves the contents the table must have in the variable Content
'The content depends on what's in the QueryString
'The form below is the form that I want to Validate using JavaScript. I want to validate all the usual items such as valid email, correct format age and salary and no fields left blank etc
if QStr="createnew" then
Content = Content & "<form name=frmCreate action=create.asp Method=post>"
Content = Content & "<tr><td ><br>Username: <input type=text name=txtUsername></td></tr>"
Content = Content & "<tr><td >Password: <input type=password name=txtPassword></td></tr>"
Content = Content & "<tr><td ><br>First name: <input type=text name=txtFirstName></td></tr>"
Content = Content & "<tr><td ><br>Surname: <input type=text name=txtLastName></td></tr>"
Content = Content & "<tr><td ><br>Address: <input type=text name=txtAddress></td></tr>"
Content = Content & "<tr><td ><br>County: <input type=text name=txtCounty></td></tr>"
Content = Content & "<tr><td ><br>Postcode: <input type=text name=txtPostcode></td></tr>"
Content = Content & "<tr><td ><br>Age: <input type=text name=txtAge></td></tr>"
Content = Content & "<tr><td ><br>Income: <input type=text name=txtAnnualIncome></td></tr>"
Content = Content & "<tr><td ><br>Gender: <input type=text name=txtGender></td></tr>"
Content = Content & "<tr><td ><br>E-mail Address: <input type=text name=txtEmail></td></tr>"
Content = Content & "<tr><td ><input type=submit name=submit value=Register <td></tr>"
Content = Content & "</form>"
%>
'The following is code is where the table is generated to show the registration form
<table border="1" cellspacing="5" width="350px">
<%
Response.Write("<tr><td valign=top align=center><strong>" & Title & "</strong></td></tr>")
Response.Write(Content) ' Paste the contents in the table
%>
</table>
If anyone knows how it can be done I would really appreciate the help.
Thanks
Gareth
|