Search This Blog

Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Tuesday, March 6, 2012

Change color of table column using jquery

If the table id is punchData and if you are changing second column color
$("#punchData > tbody > tr > td:nth-child(2)").css("background","#F5D0A9");

Tuesday, November 8, 2011

Validate numbers in JavaScript - IsNumeric()

A simple function to find if a positive number
function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

Wednesday, January 5, 2011

Date validation Java Script

function isValidDate(txtDate) {
           var objDate;  // date object initialized from the txtDate string
           var mSeconds; // milliseconds from txtDate

           // date length should be 10 characters - no more, no less
           if (txtDate.length != 10) return false;

           // extract day, month and year from the txtDate string
           // expected format is YYYY-mm-DD
           // subtraction will cast variables to integer implicitly
           var day   = txtDate.substring(8,10)  - 0;
           var month = txtDate.substring(5,7)  - 1; // because months in JS start with 0
           var year  = txtDate.substring(0,4) - 0;


          // third and sixth character should be /
           if (txtDate.substring(2,3) != '-') return false;
           if (txtDate.substring(5,6) != '-') return false;

          // test year range
           if (year < 999 || year > 3000) return false;

           // convert txtDate to the milliseconds
           mSeconds = (new Date(year, month, day)).getTime();

           // set the date object from milliseconds
           objDate = new Date();
           objDate.setTime(mSeconds);

           // if there exists difference then date isn't valid
           if (objDate.getFullYear() != year)  return false;
           if (objDate.getMonth()    != month) return false;
           if (objDate.getDate()     != day)   return false;

           // otherwise return true
          return true;

    }

Thursday, October 7, 2010

Find an element Id which match a pattern in jquery

Using jquery its possible to find an element that matches a specific pattern. This code will find each input Id and check if its greater than 24

           $("input[id^=duration_]").each(function() {

                if($(this).val()>24){
                    alert('Duration should be less than 24');
                     returnValue = false;
                }

            });
more examples