|
|
|
|
|
| | |
|
Active Server Pages ASP a directory of ASP tutorials applications scripts components and articles for the novice to professional developer. CJWSoft ASPProtect ASPBanner ASPClassifieds
(Advanced)
(Components)
(Database)
(General)
(Vbscript)

|
|
Subject: |
Re: client-side javascript code doesnt run |
From: |
Harlan |
Date: |
3/8/1999 4:35:22 PM |
IP: |
206.222.20.2 |
I think I posted this in the vi6 form, but I doubt you would have found it even if you knew it was there. Here is the function I wrote for javascript validation..
'----------------------------------------------------------------
'Name: CreateValidate()
'Purpose: Create Javascript Validate
'----------------------------------------------------------------
' Takes: comma delimited string of form elements to validate.
'----------------------------------------------------------------
' Returns: Nothing
'----------------------------------------------------------------
Sub CreateValidate(strArrayValidationFields)
%>
<Script language="JavaScript">
function Validate(objForm) {
<%
Fields = Split(strArrayValidationFields,",")
For i = 0 to UBound(Fields)
response.write vbTab & "if (objForm." & fields(i) & ".value == " & chr(34) & chr(34) & ") {" & vbCrLf
response.write vbTab & "alert(" & chr(34) & "\n" & fields(i) & " is a requried field.\nPlease complete it and try again." & chr(34) & ")" & vbCrLf
response.write vbTab & "objForm." & fields(i) & ".focus()" & vbCrLf
response.write vbTab & "}" & vbCrLf
response.write vbTab & "else "
Next%>
{
objForm.submit()
}
}
</Script>
<%
End Sub
%>
here is how you use it..
<%call CreateValidate("txtName,txtAddy")%>
<form name='frmSomeForm' method='post'>
<input type='text' name='txtName'>
<input type='text' name='txtAddy'>
<input type='text' name='txtPhone'>
<input type='Button' name='Submit' Value='Submit' onClick="Validate(this.form)">
</form>
if you notice, I'm make sure they fill in
txtName and txtAddy, but they don't have to
fill in txtPhone. You can send it as many form
input names as you want to validate. Its a
good idea to add call the sub in the <head>
rather then the body (although it works in both).
hth,
Harlan |
Previous Message
|
|

|
|
|
|
|
|
|
|
|
|