SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Java Script Question

    Hi there,

    I've got this code on my site for the script to check if certain fields in a form have been filled in, but would also like to add something to it whereby the script checks to see if the email and confemail (email confirmation) are the same.

    Is there a way to add something to this code so that I don't have to play around with it? I'm totally unfamiliar with Java Scripts, as you can tell by the free script I'm using:


    <script language="JavaScript">
    <!--
    function checkform ( form )
    {
    // see http://www.thesitewizard.com/archive/validation.shtml
    // for an explanation of this script and how to use it on your
    // own website

    // ** START **
    if (form.email.value == "") {
    alert( "Please enter your email address." );
    form.email.focus();
    return false ;
    }
    // ** END **

    // ** START **
    if (form.confemail.value == "") {
    alert( "Please confirm your email address." );
    form.confemail.focus();
    return false ;
    }
    // ** END **

    // ** START **
    if (form.fname.value == "") {
    alert( "Please enter your first name." );
    form.fname.focus();
    return false ;
    }
    // ** END **

    // ** START **
    if (form.lname.value == "") {
    alert( "Please enter your last name." );
    form.lname.focus();
    return false ;
    }
    // ** END **

    // ** START **
    if (form.subscription.value == "") {
    alert( "Please select a subscription type." );
    form.subscription.focus();
    return false ;
    }
    // ** END **
    return true ;
    }
    //-->
    </script>

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here ya go:

    Code:
    <script type="text/javascript"> 
    <!-- 
    function checkform ( form ) 
    { 
    // see http://www.thesitewizard.com/archive/validation.shtml 
    // for an explanation of this script and how to use it on your 
    // own website 
    
    // ** START ** 
    if (form.email.value == "") { 
    alert( "Please enter your email address." ); 
    form.email.focus(); 
    return false ; 
    } 
    // ** END ** 
    
    // ** START ** 
    if (form.confemail.value == "") { 
    alert( "Please confirm your email address." ); 
    form.confemail.focus(); 
    return false ; 
    } 
    // ** END ** 
    
    if (form.email.value != form.confemail.value) {
     alert("Email and confirmation do not match.");
     form.confemail.select();
     return false;
    }
    
    // ** START ** 
    if (form.fname.value == "") { 
    alert( "Please enter your first name." ); 
    form.fname.focus(); 
    return false ; 
    } 
    // ** END ** 
    
    // ** START ** 
    if (form.lname.value == "") { 
    alert( "Please enter your last name." ); 
    form.lname.focus(); 
    return false ; 
    } 
    // ** END ** 
    
    // ** START ** 
    if (form.subscription.value == "") { 
    alert( "Please select a subscription type." ); 
    form.subscription.focus(); 
    return false ; 
    } 
    // ** END ** 
    return true ; 
    } 
    //--> 
    </script>
    ck :: bringing chris to the masses.

  3. #3
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    WOW!

    Thanks Anarchos


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
  •