#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    11
    Rep Power
    0

    Question FORM Validation with JavaScript


    Form Validation with JavaScript Hi there,

    I know its possible to use JavaScript to validate a form but so far I`ve only found a way of making a POPUP message appear with the error "i.e. You forgot to add your surname"

    Does anyone know of a way of bypassing the display of a msgbox and instead returning the user to the field in question (getfocus) and highlighting it

    i.e Surname Field label turns red to show a required entry.

    I need this to be done on client side rather than server-side..

    Any comments, suggestions or tutorials would be gratefully received..

    Thanks in advance.

    Jamie You can read the article here .
  2. #2
  3. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    38
    What you want to do is replace (in the validation code you found) the code to display an alert() or confirm() with form.field.focus(), where form is the name of the form, and field is the name of the field in question. However, I would recommend performing a combination of the two, because somehow you still need to inform the user why their form didn't submit as they expected it to.
    Michael
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    81
    Rep Power
    14
    I have some tutorials and example scripts here:

    Form Validation Step-by-Step
    http://javascript.about.com/library/.../aa070901a.htm

    Form Scripts
    http://javascript.about.com/cs/formscripts/index.htm

    And as peiux suggest, using a combination of message box + focus, works best. As this example script illustrates:

    http://javascript.about.com/library/...rmvalidate.htm
    Robert Dominy
    About Guide for JavaScript
    http://javascript.about.com
    Software Consulting & Development
    http://www.angusog.com
  6. #4
  7. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    38
    <chant>
    'I' before 'E', except after 'C'...
    'I' before 'E', except after 'C'...
    'I' before 'E', except after 'C'...
    </chant>

    Michael
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    81
    Rep Power
    14
    Sorry about that pieux! I was applying the special exception rule:

    i before e except before ux

    Robert Dominy
    About Guide for JavaScript
    http://javascript.about.com
    Software Consulting & Development
    http://www.angusog.com

IMN logo majestic logo threadwatch logo seochat tools logo