Greetings. This post is related to my recent post, and
may better explain what I am trying to do .... hopefully :-
)

Question, what is the most efficient way to validate data
in a form? For instance, I know I can do something like
this:

Function Form1_onSubmit()

If Form1.txtuser1.Value = "" Then
' do something here
End If

If Form1.txtuser2.Value = "" Then
' do something here
End If

End Function

However, what if I have several like fields, e.g.
txtuser1, txtuser2, txtuser3, etc. ... in that case the
above approach to data validation is not very efficient.
Especially when I want to run several like fields against
the same validation methods (i.e. is it blank, does it or
does it not contain this or that character?). To further
complicate matters, what if the amount of like fields I
have on my page will vary on each load because they are
created "dynamically" thru ASP code? In that case, there
is no way to setup the above, functional albeit
inefficient, method of validating my data. In a nutshell,
what I am trying to accomplish on the client-side is what
I can rather easily do on the server-side:

For x = 1 To Request.Form.count()

strFrmKey = Request.Form.key(x)
strFrmItm = Request.Form.item(x)

' Do whatever other checking I would like here

Next

Is there, or what is an equivalent for client-side
validation? Any and all answers are greatly appreciated.

Doug

Re: Form data validation methods by Gurgen

Gurgen
Tue Sep 16 19:43:48 CDT 2003

Form1_onSubmit() is not an efficient way to use for the form validation, because regardless of the outcome of the validation the
form will be submitted anyway.
You should create a regular sub, call it from button onclick event and at the end of the sub (if everything is valid) use
Form1.Submit. Otherwise display a message to correct appropriate fields.

Example:

---------------------------------------------------
<script language="VBscript">
Sub formSubmit()

Set objElements = document.Form1.Elements
For Each objElement in objElements
If objElement.type = "text" Then

If objElement.value = "" then
msgbox("All fields must be filled!")
Exit Sub
End If
End If
Next

Form1.Submit

End Sub
</script>

<form method="POST" name="Form1" action="test.asp">

<p><input type="text" name="T1" size="20">
<input type="Button" value="Button" name="B1" onclick="formSubmit()">
<input type="reset" value="Reset" name="B2">
<input type="text" name="T2" size="20"></p>

</form>
--------------------------------------------------


See if this helps..

Gurgen.

"doug" <dougpart@adelphia.net> wrote in message news:07ec01c37cb0$dae95940$a101280a@phx.gbl...
> Greetings. This post is related to my recent post, and
> may better explain what I am trying to do .... hopefully :-
> )
>
> Question, what is the most efficient way to validate data
> in a form? For instance, I know I can do something like
> this:
>
> Function Form1_onSubmit()
>
> If Form1.txtuser1.Value = "" Then
> ' do something here
> End If
>
> If Form1.txtuser2.Value = "" Then
> ' do something here
> End If
>
> End Function
>
> However, what if I have several like fields, e.g.
> txtuser1, txtuser2, txtuser3, etc. ... in that case the
> above approach to data validation is not very efficient.
> Especially when I want to run several like fields against
> the same validation methods (i.e. is it blank, does it or
> does it not contain this or that character?). To further
> complicate matters, what if the amount of like fields I
> have on my page will vary on each load because they are
> created "dynamically" thru ASP code? In that case, there
> is no way to setup the above, functional albeit
> inefficient, method of validating my data. In a nutshell,
> what I am trying to accomplish on the client-side is what
> I can rather easily do on the server-side:
>
> For x = 1 To Request.Form.count()
>
> strFrmKey = Request.Form.key(x)
> strFrmItm = Request.Form.item(x)
>
> ' Do whatever other checking I would like here
>
> Next
>
> Is there, or what is an equivalent for client-side
> validation? Any and all answers are greatly appreciated.
>
> Doug
>
>
>



Re: Form data validation methods by Steve

Steve
Wed Sep 17 07:37:08 CDT 2003

Gurgen wrote:
> Form1_onSubmit() is not an efficient way to use for the form validation,
> because regardless of the outcome of the validation the form will be
> submitted anyway.

???

<html>
<head>
<title></title>
<script language="vbscript" type="text/vbscript">
Function Form1_onSubmit
window.event.returnValue = window.confirm("Submit?")
End Function
</script>
</head>
<body>
<form name="Form1" action="javascript:void alert('Submitted')">
<input type="submit">
</form>
</body>
</html>

--
Steve

The man who views the world at 50 the same as he did at 20 has wasted 30 years
of his life. -Muhammad Ali