#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Singapore
    Posts
    6
    Rep Power
    0

    Need some help on Netscape 4.7 in Javascript


    I'm having problems with Javascript in Netscape 4.7. So please help me take a look at the codes, I would appreciate very much...

    function chkDate()
    {
    var smonth = changeMth(document.f1.StartMonth.options[document.f1.StartMonth.selectedIndex].value);
    var syear = document.f1.StartYear.options[document.f1.StartYear.selectedIndex].value;
    var emonth = changeMth(document.f1.EndMonth.options[document.f1.EndMonth.selectedIndex].value);
    var eyear = document.f1.EndYear.options[document.f1.EndYear.selectedIndex].value;
    if(smonth > emonth) return false;
    if(syear > eyear) return false;
    return true;
    }
    function changeMth(val)
    {
    if(val=="January")
    return "1";
    else if(val=="February")
    return "2";
    else if(val=="March")
    return "3";
    else if(val== "April")
    return "4";
    else if(val== "May")
    return "5";
    else if(val== "June")
    return "6";
    else if(val== "July")
    return "7";
    else if(val== "August")
    return "8";
    else if(val== "September")
    return "9";
    else if(val== "October")
    return "10";
    else if(val== "November")
    return "11";
    else if(val== "December")
    return "12";
    }

    Note: this codes are enclosed in the script tag...
  2. #2
  3. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    We're not psychics here (not me, anyway) so, in the future, please post your HTML as well, a description of what you're up to - in this case it looks like a form validator, but who knows how you're implementing it - and a word or two specifying the nature of the 'problem'. Hopefully this will help:


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">

    function chkDate(oForm) {
    var oSel, selectname = new Array('Start_Month' , 'End_Month' , 'Start_Year' , 'End_Year');
    for (var i=0; i<selectname.length; ++i) {
    oSel = oForm[selectname[i]]; //get list
    if (oSel.selectedIndex == 0) { //no option selected
    alert('Please make a selection from the ' + selectname[i].split('_').join(' ') + ' list.');
    oSel.focus();
    return false;
    }
    }
    if ((oForm['Start_Year'].selectedIndex == oForm['End_Year'].selectedIndex) &&
    (oForm['Start_Month'].selectedIndex >= oForm['End_Month'].selectedIndex)) {
    alert('Please choose:\n\nAn End Month later than the Start Month\n-or-\nAn End Year later than the Start Year.\n\n');
    oForm['End_Month'].focus();
    return false;
    }
    if (oForm['Start_Year'].selectedIndex > oForm['End_Year'].selectedIndex) {
    alert('Please choose an End Year the same or later than your selected Start Year.');
    oForm['End_Year'].focus();
    return false;
    }
    return true;
    }

    </script>
    </head>
    <body>
    <form name="f1" action="javascript&#58;alert('ok')" method="post" onsubmit="return chkDate(this)">
    Start Month&amp;nbsp;<select name="Start_Month">
    <option>CHOOSE</option>
    <option value="January">January</option>
    <option value="February">February</option>
    <option value="March">March</option>
    <option value="April">April</option>
    <option value="May">May</option>
    <option value="June">June</option>
    <option value="July">July</option>
    <option value="August">August</option>
    <option value="September">September</option>
    <option value="October">October</option>
    <option value="November">November</option>
    <option value="December">December</option>
    </select><br>
    End Month&amp;nbsp;&amp;nbsp;<select name="End_Month">
    <option>CHOOSE</option>
    <option value="January">January</option>
    <option value="February">February</option>
    <option value="March">March</option>
    <option value="April">April</option>
    <option value="May">May</option>
    <option value="June">June</option>
    <option value="July">July</option>
    <option value="August">August</option>
    <option value="September">September</option>
    <option value="October">October</option>
    <option value="November">November</option>
    <option value="December">December</option>
    </select><br>
    Start Year&amp;nbsp;&amp;nbsp;&amp;nbsp;<select name="Start_Year">
    <option>CHOOSE</option>
    <option value="2003">2003</option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    </select><br>
    End Year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;<select name="End_Year">
    <option>CHOOSE</option>
    <option value="2003">2003</option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    </select><br><br>
    <input type="submit">
    </form>
    </body>
    </html>

    You can type in 'mocha:' to the location field in Navigator & hit 'enter' to see if any specific errors have occurred.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Singapore
    Posts
    6
    Rep Power
    0
    Sorry... It's my first time posting a question in a forum... So I missed the html codes...

    This is the javascript codes again:
    <script language="JavaScript">
    <!--
    function validate()
    {
    var smonth = document.f1.StartMonth.options[document.f1.StartMonth.selectedIndex].value;
    var syear = document.f1.StartYear.options[document.f1.StartYear.selectedIndex].value;
    var emonth = document.f1.EndMonth.options[document.f1.EndMonth.selectedIndex].value;
    var eyear = document.f1.EndYear.options[document.f1.EndYear.selectedIndex].value;
    if(smonth=="" || smonth==null) return false;
    if(syear=="" || syear==null) return false;
    if(emonth=="" || emonth==null) return false;
    if(eyear=="" || eyear==null) return false;
    return true;
    }

    function chkDate()
    {
    var smonth = changeMth(document.f1.StartMonth.options[document.f1.StartMonth.selectedIndex].value);
    var syear = document.f1.StartYear.options[document.f1.StartYear.selectedIndex].value;
    var emonth = changeMth(document.f1.EndMonth.options[document.f1.EndMonth.selectedIndex].value);
    var eyear = document.f1.EndYear.options[document.f1.EndYear.selectedIndex].value;
    if(smonth > emonth) return false;
    if(syear > eyear) return false;
    return true;
    }

    function chk()
    {
    if(validate())
    {
    if(chkDate())
    {
    document.f1.action = 'admintasks_auditlog.jsp';
    document.f1.submit();
    }
    else
    {
    alert("Start Date should not be greater than End Date.");
    return false;
    }
    }
    else
    {
    alert("Values of fields should not be null. Please select fields before proceeding.");
    return false;
    }
    }
    function changeMth(val)
    {
    if(val=="January")
    return "1";
    else if(val=="February")
    return "2";
    else if(val=="March")
    return "3";
    else if(val== "April")
    return "4";
    else if(val== "May")
    return "5";
    else if(val== "June")
    return "6";
    else if(val== "July")
    return "7";
    else if(val== "August")
    return "8";
    else if(val== "September")
    return "9";
    else if(val== "October")
    return "10";
    else if(val== "November")
    return "11";
    else if(val== "December")
    return "12";
    }
    </script>

    This is the html codes:

    <form name="f1" method="post" onSubmit="return chk();">

    <select name="StartMonth" id="StartMonth">
    <option value="" selected>Month</option>
    <option value="January">January</option>
    <option value="February">February</option>
    <option value="March">March</option>
    <option value="April">April</option>
    <option value="May">May</option>
    <option value="June">June</option>
    <option value="July">July</option>
    <option value="August">August</option>
    <option value="September">September</option>
    <option value="October">October</option>
    <option value="November">November</option>
    <option value="December">December</option>
    </select>

    <select name="StartYear" id="StartYear">
    <option value="" selected>Year</option>
    <option value="2004">2004</option>
    <option value="2003">2003</option>
    <option value="2002">2002</option>
    <option value="2001">2001</option>
    <option value="2000">2000</option>
    </select>

    <select name="EndMonth" id="EndMonth">
    <option value="" selected>Month</option>
    <option value="January">January</option>
    <option value="February">February</option>
    <option value="March">March</option>
    <option value="April">April</option>
    <option value="May">May</option>
    <option value="June">June</option>
    <option value="July">July</option>
    <option value="August">August</option>
    <option value="September">September</option>
    <option value="October">October</option>
    <option value="November">November</option>
    <option value="December">December</option>
    </select>

    <select name="EndYear" id="EndYear">
    <option value=""selected>Year</option>
    <option value="2004">2004</option>
    <option value="2003">2003</option>
    <option value="2002">2002</option>
    <option value="2001">2001</option>
    <option value="2000">2000</option>
    </select>

    </form>

    I'm checking for null value and also checking that the start date should not be greater than the end date...

    I apologize for being careless....
  6. #4
  7. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    All is forgiven []. Did you run the code I posted? See if it's what you're looking for (done a slew of these).
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Singapore
    Posts
    6
    Rep Power
    0
    I can't use the code... I kept on having javascript error.... Something about syntax error... The page is unable to detect the chkDate()... It says undefine chkDate()...
  10. #6
  11. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    Where is the submit button? If there is one....

    You're submitting the form twice.

    1) <form name="f1" method="post" onSubmit="return chk();">

    2) if(chkDate())
    {
    document.f1.action = 'admintasks_auditlog.jsp';
    document.f1.submit();
    }

    Just set the action in HTML, lose the JavaScript submit() and return true to submit the form.
    Last edited by adios; January 29th, 2003 at 12:04 AM.
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Singapore
    Posts
    6
    Rep Power
    0
    Even if I submit the form another time, there is no error rite...
    I found out the problem of my codes... I did not delete the <-- of the javascript, thus the function are all in comments....

    Tks for the time and help you give....

IMN logo majestic logo threadwatch logo seochat tools logo