SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    England
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Validation does not work.. it submits anyway

    hi,

    I am, validating a form and it seems to half work. An alert is displayed when there is a field missing, but the form still submits. ANy ideas?

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var commission;
    var sub_total;
    var countryvalue;
    var SourceCountry;
    var expenditure;
    var msg="";

    function validate() {
    if(_DominoForm.expenditure.value=="") {
    msg="\nYou must enter an expenditure";
    }
    if(_DominoForm.SelectSourceCountry.value == "Select Country") {
    msg=(msg + "\n You must select the country");
    }
    if(msg=="") {
    alert("it works");
    return true;
    }
    else{
    alert(msg);
    return false;
    }
    }

    </HEAD>
    <BODY TEXT="000000" BGCOLOR="white">

    <FORM onSubmit="validate()" METHOD=post ACTION="wbm_content_SIAL.nsf/sc-1?OpenForm&Seq=1" NAME="_DominoForm">


    <INPUT NAME="name" VALUE="">
    <INPUT NAME="email" VALUE="">
    <INPUT NAME="telephone" VALUE="">


    <SELECT NAME="SelectSourceCountry" onchange="calculate(this.form)">
    <OPTION VALUE="Select Country">Select Country
    <OPTION VALUE="England">England
    <OPTION VALUE="France">France
    <OPTION VALUE="Germany">Germany
    <OPTION VALUE="Japan">Japan
    <OPTION VALUE="Singapore">Singapore</SELECT>


    <SELECT NAME="CommodityArea" onchange="calculate(this.form)">
    <OPTION VALUE="Construction - GSC">Construction - GSC</SELECT>


    <SELECT NAME="CustomsDescription">
    <OPTION>Jackets &amp; Blazers</SELECT>

    <INPUT NAME="expenditure" VALUE="" onchange="calculate(this.form)">

    <INPUT NAME="commission" VALUE="" value=0 onchange="calculate(this.form)">

    <INPUT NAME="total" VALUE="" disabled>
    <input type=submit value="ADD" >
    </form>

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi kjc2,

    one little thing...
    Code:
    <form onsubmit="return validate()" ...

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    England
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh...

    thank you


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
  •