SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    --------------------------------------------------------------------------------
    I am using a javascript form validator, which works in IE, although it complains that the "frm = document.poForm;" line is not an object. But in Netscape anytime a submit button is clicked, the alert msg box pops up and beeps, whether or no the field is correct.

    I include here the javascript from the HTML page and the relevant part of the validate.js file

    ***********************************
    Validate.js::
    // Check if Field contains a valid date of the form dd/mm/yy
    function IsValidDate(Field)
    {
    if (!ContainsSomething(Field))
    {
    return false;
    }
    var indate=Field.value;
    var sdate = indate.split("/")

    var chkDate = new Date(Date.parse(indate))

    var cmpDate = (chkDate.getMonth()+1)+
    "/"+(chkDate.getDate())+
    "/"+(chkDate.getYear())
    var indate2 = (Math.abs(sdate[0]))+"/"+(
    Math.abs(sdate[1]))+
    "/"+(Math.abs(sdate[2]))
    if (indate2 != cmpDate || cmpDate == "NaN/NaN/NaN")
    {
    return false
    }
    else
    {
    return true;
    }
    }



    The HTML script
    *********************************************
    <script language="JavaScript"><!--
    // Generator: Validator 98
    function CheckForm()
    {
    //msg = ""; // **DEBUG ONLY**
    frm = form.document.poForm;
    for ( y=1; y <= frm.itemCount.value; ++y )
    {
    fld = frm.elements["drawdeldate"+y];
    //msg += ( fld.name + ": " + fld.value + "\n" ); // **DEBUG**
    //if ( fld.value == "" ) // CHANGE TO CALL IsValidDate !!
    if (!IsValidDate(fld))
    {
    alert ("Please insert a Drawing Delivery date in the format mm/dd/yyyy for item " + y);
    fld.focus( );
    return false;
    }

    fld = frm.elements["equipdeldate"+y];
    //msg += ( fld.name + ": " + fld.value + "\n" ); // **DEBUG**
    //if ( fld.value == "" ) // CHANGE TO CALL IsValidDate !!
    if (!IsValidDate(fld))
    {
    alert ("Please insert an Equipment Delivery date in the format mm/dd/yyyy for item " + y);
    fld.focus( );
    return false;
    }

    }



    //alert(msg); // **DEBUG**
    return true;
    }

    // ************************* END OF SCRIPT *****************

    // --></Script>

  2. #2
    SitePoint Zealot Atirez's Avatar
    Join Date
    Nov 2000
    Location
    England
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am no expert when it comes to JavaScript but has it got something to do with this:

    frm = form.document.poForm;

    Having to be frm = document.form['poForm'];

    That is if the form is called poForm which I am assuming since you didnt actually enter the form html or give the form name you want the script to validate.

    Hope this is what you want.

  3. #3
    SitePoint Member
    Join Date
    Sep 2000
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To comment, by going over your code, with not too much of a fine tooth comb, it looks like your call to get the form information is off.

    to call a form object you need to call it in the following order:

    Document.formname.fieldname

    ie:

    document.form.name.length would give you the length of the input in that field in the form

    where:

    form is the name of the form
    name is the name of the field name in question
    lenght is the attribute that you are asking for this paticular call.


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
  •