|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi there I want this form to do client side validation by checking that the user has entered at least 1 character in each of my fields on the form. The problem is it does not seem to work and jumps through to the asp page and reports an error of 'customers.Password' cannot be a zero-length string. I know this as my database is set for this. But the form should check the fields first before posting to the asp page or am i missing something.
plz be gentle as I am new to this and thank you <html> <TABLE WIDTH="600" CELLPADDING="10" CELLSPACING="0" ALIGN="CENTER" Background="1.jpg" BORDER="2"> <TR> <TD><BR> <CENTER> <script language = "VBScript"> option explicit private sub chkformdata() dim tempfirst, templast dim temppass, tempcity, temppost, temphone dim tempmail tempfirst= signup.firstname.value templast = signup.lastname.value tempmail = signup.e-mail.value temppass = signup.password.value tempcity = signup.city.value temppost = signup.postcode.value temphone = signup.homephone.value if len(tempfirst) = 0 then msgbox("Sorry you have not entered a valid first name. It must be at least 1 character long ") else if len(templast) = 0 then msgbox("Sorry you have not entered a valid Last Name.It must be at least 1 character long ") else if len(tempmail) = 0 then msgbox("Sorry you have not entered a valid E-mail address.It must be at least 1 character long ") else if len(temppass) = 0 then msgbox("Sorry you have not entered a valid Password.It must be at least 1 character long ") else if len(tempcity) = 0 then msgbox("Sorry you have not entered a valid City.It must be at least 1 character long ") else if len(temppost) = 0 then msgbox("Sorry you have not entered a valid Post Code.It must be at least 1 character long ") else if len(temphone) = 0 then msgbox("Sorry you have not entered a valid Phone Number.It must be at least 1 character long ") End if End If End If End if End if end if end if end sub </script> </head> <BODY text = "yellow" body background="1.jpg" LINK="iceblue" VLINK="white"> <form name="signup" action="customer.asp" method="post"> <table border=0 cellpadding=0 align=center cellspacing=0 BGCOLOR="navy"> <td> <tr> <align=right>First name: <input type="text" name="FirstName" value=""> <align=right>Last name: <input type="text" name="LastName" value=""> <align=right>E-Mail: <input type="text" name="e-mail" value=""> <align=right>Password: <input type="password" name="password" value=""> <align=right>City: <input type="text" name="city" value="" value=""> <align=right>Postal Code: <input type="text" name="postcode" value=""> <align=right>Phone Number: <input type="text" name="HomePhone" value=""> <input type="submit" value="Submit" align="center" onClick = "chkformdata()"> <input type="Reset" value="Reset" align="center"> </tr> </table> </form> </html> Last edited by senrag : May 25th, 2004 at 05:23 PM. |
|
#2
|
||||
|
||||
|
Your sub must be a function and the function should return false if submitting is not allowed.
And change the input to: <input type="submit" value="Submit" align="center" onClick = "return chkformdata()"> That should do the trick... |
|
#3
|
|||
|
|||
|
I have done a similar one using ASP.Just have the data entered by the user stored in some variable like this
<% firstname=Request.Form("firstname") lastname=Request.Form("lastname") ...... if firstname="" then %> <script language="JavaScript"> alert("Firstname not entered") </script> <% response.end end if %> This will check whether the user has entered some values or skipped it.If the user has not entered any value the program will terminate.The program will be executed one and only if all the conditions given by you are satisfied. Hope you got some idea. |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Please help with form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|