Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Form Validating
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Form Validating

 Post Reply Post Reply Page  <12
Author
maniva View Drop Down
Groupie
Groupie
Avatar

Joined: 04 April 2002
Location: Italy
Status: Offline
Points: 82
Post Options Post Options   Thanks (0) Thanks(0)   Quote maniva Quote  Post ReplyReply Direct Link To This Post Posted: 10 March 2003 at 3:12am

I don't like alert in javascript.
I would like to display a red message near the wrong field.

Ivano Mangiarotti
Back to Top
Gary View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 March 2002
Location: United Kingdom
Status: Offline
Points: 326
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gary Quote  Post ReplyReply Direct Link To This Post Posted: 10 March 2003 at 3:19am

You could do something else with javascript.....

Change the background color of all form elements that are incorrect/incomplete.

Place somekind of image/message next to each element and set the visibility property to hidden. When you run the validation script, change the visibility to visible on all elements that fail.

This would be a lot easier and economical than validating on a different page - especially if you're going to redirect back when validation fails.

Back to Top
maniva View Drop Down
Groupie
Groupie
Avatar

Joined: 04 April 2002
Location: Italy
Status: Offline
Points: 82
Post Options Post Options   Thanks (0) Thanks(0)   Quote maniva Quote  Post ReplyReply Direct Link To This Post Posted: 10 March 2003 at 3:38am

Could you give me an example with explanation in changing colors etc.

I've some data field, numeric and text.

Thanks a lot

 

Ivano Mangiarotti
Back to Top
Gary View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 March 2002
Location: United Kingdom
Status: Offline
Points: 326
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gary Quote  Post ReplyReply Direct Link To This Post Posted: 10 March 2003 at 4:09am

Here you go.....
Basically there are 2 inputs on the form which are validated (one to see if anything has been entered and the other to check if a number > 0 has been entered).

Hope this helps

<script language="Javascript">
function ValidateForm()
{
 document.myForm.ErrCheck.value = "";
 ErrMsg = 'ERROR - Incomplete Data' + '\n' + '\n';
 if (document.myForm.txtA.value == "")
  {
  ErrMsg = ErrMsg + 'You need to specify your name.' + '\n';
  document.copyrequest.ErrCheck.value = "Error";
  document.copyrequest.FileName.style.backgroundColor='#ff0000';
  }

 if (isNaN(document.myForm.intB.value) || document.myForm.intB.value < 1)
  {
  ErrMsg = ErrMsg + 'You need to specify your age.' + '\n';
  document.myForm.ErrCheck.value = "Error";
  }

 if (document.copyrequest.ErrCheck.value == "Error")
   {
   alert(ErrMsg);
   }
 else
 {
  document.copyrequest.submit();
 }
}
</script>

<form name="myForm" action="page.asp" method=-"post">
<input name="ErrCheck" type="hidden">
Name: <input name="txtA" type="text">
Age (Years): <input name="intB" type="text">
</form>

<input type="button" value="Valid" onClick="ValidateForm()">

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 10 March 2003 at 3:30pm
Originally posted by Gary Gary wrote:

You could do something else with javascript.....

Change the background color of all form elements that are incorrect/incomplete.

Place somekind of image/message next to each element and set the visibility property to hidden. When you run the validation script, change the visibility to visible on all elements that fail.

This would be a lot easier and economical than validating on a different page - especially if you're going to redirect back when validation fails.

If this is any sort of serious site, I wouldn't rely on client-side validation. It can be circumvented quite easily.

Client-side validation is for the 'cosmetic benefit' of your users. A complete server-side validation process should always be performed, irrespective of whether you use client-side validation or not.

http://www.adopenstatic.com/resources/code/UIValidation.asp

Cheers,
Andrew

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
maniva View Drop Down
Groupie
Groupie
Avatar

Joined: 04 April 2002
Location: Italy
Status: Offline
Points: 82
Post Options Post Options   Thanks (0) Thanks(0)   Quote maniva Quote  Post ReplyReply Direct Link To This Post Posted: 11 March 2003 at 1:56am

Thank you vary much Gary.

I will  try immediately

Ivano Mangiarotti
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.