www.webdeveloper.com
Results 1 to 2 of 2

Thread: JavaScript: month-year validation

  1. #1
    Join Date
    Oct 2004
    Posts
    169

    Lightbulb JavaScript: month-year validation

    i have a select type options in which we can select month and year options.

    if we select future month and year, it shows error message and clear the select type options.

    i have made a script as show below: buit its not working properly.



    script:


    function dropdown_validator()
    {
    // Variables for the current date, year and month
    var right_now=new Date();
    var the_year=right_now.getYear();
    var the_month=right_now.getMonth();

    // Check to see if the request is within the current year and month
    if (payment_voucher.year.value == the_year && payment_voucher.month.value > the_month)
    {
    alert("Please check the month of your request.");
    return true;
    }


    // Check to see if the year request is calid
    if (payment_voucher.year.value > the_year)
    {
    alert("Please check the year of your request.");
    return(false);
    }
    // Comment out the alert below and change the location to your destination
    //alert("The request is valid\nMonth = "+ payment_voucher.month.value +"\nYear = "+ payment_voucher.year.value);
    // window.location.replace= dropdown_form.u_month.value + dropdown_form.u_year.value
    return(true);
    }





    form:


    <form name="payment_voucher" ACTION="" METHOD="POST" >
    <center>Current Processing Month:<select size="1" name="month" onblur="return dropdown_validator()" >
    <option value="">Month</option>
    <option value="1">Jan</option>
    <option value="2">Feb</option>
    <option value="3">Mar</option>
    <option value="4">Apr</option>
    <option value="5">May</option>
    <option value="6">Jun</option>
    <option value="7">Jul</option>
    <option value="8">Aug</option>
    <option value="9">Sep</option>
    <option value="10">Oct</option>
    <option value="11">Nov</option>
    <option value="12">Dec</option>
    </select>

    <select size="1" name="year" onblur="return dropdown_validator()">
    <option value="">Year</option>
    <option value=2010>2010</option>
    <option value=2009>2009</option>
    <option value=2008>2008</option>
    <option value=2007>2007</option>
    <option value=2006>2006</option>
    <option value=2005>2005</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>
    <option value="1999">1999</option>
    <option value="1998">1998</option>
    </select><br><br></center>


    plz help me


    abhijit

  2. #2
    Join Date
    Oct 2004
    Location
    UK
    Posts
    208
    You should post the HTML page that you have the code from, that way people can see and work with thecode to iron out any issues you may have or offer advice.

    I have looked at your snippits and cant tell much from it other than your ommitting the document. portion of the objects. and your checks need to be >= and not just > ,what if the person uses the voucher in this year && this month, it wouldn't validate.
    Ther is no software substitute for proper configuration...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles