SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FORM: unable to store the values in fields: overwriting?

    I make a routine check in my form for the fields' emptiness. If the field is empty, alert appears, and focus should move to the field. The rest of fields should still have their contents.

    This works, but the focus appears just for a moment, and then disappears. Content of other fields (already full of information) ALSO DISAPPEARS, as if the page is "overwritten".

    The very annoying is that I use my old code which worked before! Here is it

    .....
    if(document.regform.first_name.value=="")
    {
    alert("Please, type your first name")
    document.regform.first_name.focus()
    return
    }
    .....

    That time, the page with form was opened as a window (now as _blank). But opening as a window also does not help! I just got crazy What could be wrong?

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to return a false value to OnSubmit() event if validation fails.
    Try this code,
    Code:
    <html>
    <script language="javascript" type="text/javascript">
     function paulcheck() {
       if (document.f.i1.value == "") {
           alert("Please, type your first name!!") 
           document.f.i1.focus();
           return false;
       } else
           return true; 
     }
    </script>
    <body>
    
    <form name="f" onsubmit="return paulcheck();">
     input 1 <input type="text" value="" name="i1"><br>
     input 2 <input type="text" value="" name="i2"><br>
     <input type="submit" value="send">
    </form>
    
    </body>
    </html>
    Paul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •