Thanks in advance
1) Client-side: Use javascript to check the form data before it is posted.
2) Server-side: Use ASP to check the posted data and react accordingly
3) Use both - which is, needless to say, the recommended route IMHO
The scenario you talk about comes under category 1), and and would use
Javascript. In my case, this is usually not a problem since most of my work
is intranet based, so I know about my clients. If your project is on the
internet, you should proceed with caution - 13% of users do not have
javascript or have it disabled. If you are prepared to risk this, or if this
is not an issue, I can send you a client-side validation scipt that I use -
you can modify to fit your needs.
Clearly you could just opt for a server-side validation solution; the
disadvantage is that it requires a few more trips across the lines, and it
is slightly different to code, but it would work for all clients. If you
want to be as inclusive and thorough as possible you should choose this
option.
In most of my apps, I use client-side validation to check that numeric
fields are indeed numeric, mandatory fields or filled in, listboxes have
selected items etc... When the forms are submitted, I do further checks,
including checks for SQL injection. The client-side validation checks the
basics, and the server-side validations looks into the detail.
I realise that this is quite a 'shotgun response' to your question, but I'm
trying look at a broader scope. Yes, you can achieve what you asked using
javascript, but whether you should is up to you.
Chris
http://www.brightnorth.com/snippets/
'validation master' is the full readable version, 'validation.js' is the
crunched version (half the size)
"Danny" <danny...@hotmail.com> wrote in message
news:Jlmqc.44422$MH.13...@news4.srv.hcvlny.cv.net...
David H.
http://www.gatewayorlando.com/content/reservationRequestV3_submit.asp
This is a fair point, which is particularly relevant to one-off pages or to
complex validation routines. In my pages, I'm using the same js script again
& again - the first time you call a validated page you have an extra 6k to
download (not a huge amount!). Any subsequent page that uses the same
validation routines uses the cached version, which obviously has no
bandwidth overhead.
>My thinking is that I'd prefer another round-trip
> to the server as oppposed to having the visitor wait for the page to
> load.
Unless your validation routine is THAT big, the client-side method will
usually still be the quicker.
> It also allowed me to hide some validation that I'd prefer to keep
> private.
>
Which is probably one of the best reasons you could give. Fair point.
CJM
Thanks for both of your responses.
and thank you CJM for hte code. I look forward to experimenting.
David, i like the server side method as well.
But how do you handle this.
Do you give them back the same form with a message at the top? IF so, how
do you ensure the form still has the user data so they don't have to type it
all in again, also, do you call the same .asp page?
Thanks in advance
Danny
reservationRequestV3_Validation.asp
reservationRequestV3_Processing.asp
reservationRequestV3_InvalidCenter.asp
_Validation.asp obviously handles the validation. I approached the
validation by writing functions to validate the various TYPES of fields
(i.e. all text, phone number, select list, etc.) Then I use an variable
to capture the error returned by the function for the particular field
and if neccessary any applicable text message. The variables are named
(userNameValidationError, responseMethodValidationError,
userPhoneHomeValidationError, userPhoneHomeValidationText, etc.)
If all of the _validationError variables = 0, _Processing is executed to
process the request. '0' assumes that no error occurred.
If one or more of the _validationError variables <> 0, the
_InvalidCenter script executes. This script sends a new form to the
visitor indicating which fields are valid and which are not. If a
particular value is valid, a HIDDEN input is written with the value set
to <%resposne.write request("fieldName")%> to maintain the original
value. The value is then written as text to display it for reference. If
the value is invalid, a form field is written.
if nameValidationError = 0 then
'write a hidden form field with the value set to the NAME
'write the actual value as text so the user can see it
else
'write a form field with the value and highlight the field
'write an error message explaining the problem
end if
The INVALID FORM submits to _Validation.asp to allow the process to
execute again if needed.
I choose to split up the three scripts to make life easier in making
changes and debuggin since if all three were combined the total number
of lines would be horendeous(sp).
David H.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!