Tag Archives: JavaScript

what JavaScript date gives you?

In my previous post I was trying to format date, and I noticed that I was not getting it correctly. Why was that, I assembled a small script to test all accessor methods provided by Date. Here is that code.

var today = new Date();
var message = "All accessor methods of date \n\n\n" +
    "getDate(): " + today.getDate() + "\n" +
    "getDay(): " + today.getDay() + "\n" +
    "getFullYear(): " + today.getFullYear() + "\n" +
    "getHours(): " + today.getHours() + "\n" +
    "getMilliseconds(): " + today.getMilliseconds() + "\n" +
    "getMinutes(): " + today.getMinutes() + "\n" +
    "getMonth(): " + today.getMonth() + "\n" +
    "getSeconds(): " + today.getSeconds() + "\n" +
    "getTime(): " + today.getTime() + "\n" +
    "getTimezoneOffset(): " + today.getTimezoneOffset() + "\n" +
    "getUTCDate(): " + today.getUTCDate() + "\n" +
    "getUTCDay(): " + today.getUTCDay() + "\n" +
    "getUTCFullYear(): " + today.getUTCFullYear() + "\n" +
    "getUTCHours(): " + today.getUTCHours() + "\n" +
    "getUTCMilliseconds(): " + today.getUTCMilliseconds() + "\n" +
    "getUTCMinutes(): " + today.getUTCMinutes() + "\n" +
    "getUTCMonth(): " + today.getUTCMonth() + "\n" +
    "getUTCSeconds(): " + today.getUTCSeconds() + "\n" +
    "getYear(): " + today.getYear() + "\n" +
    "toDateString(): " + today.toDateString() + "\n" +
    "toGMTString(): " + today.toGMTString() + "\n" +
    "toLocaleDateString(): " + today.toLocaleDateString() + "\n" +
    "toLocaleString(): " + today.toLocaleString() + "\n" +
    "toString(): " + today.toString() + "\n" +
    "toTimeString(): " + today.toTimeString() + "\n" +
    "toUTCString(): " + today.toUTCString();
alert(message);

Continue reading

formatting dates using JavaScript

Today I was working on a task which involved manipulating dates on client-side using JavaScript. Initially I found myself quite dumb, and did not had a clue how to do it.

Then I started experimenting, which is how I learn small things. unusual results:

  • string is not a date
  • conversion to date is not easy on my format (mm/dd/yyyy)
  • formatting a date on a particular format is not easy too

So looked around, I found Datejs, which I did not wanted to use, as my task was not so much complex. Then I found some other good resources, who helped me complete this tasks.

Continue reading

Google like auto complete suggestions

I like Google’s suggest feature and was thinking of using it in any of my project. ASP.NET’s AJAX Control Toolkit have a similar control (AutoCompleteExtender) which provides a basic items to complete this functionality. I searched about its usage, and found many examples, but I was not satisfied with them. They all were populating only a single field using this extender.

I then came up with an idea, why not fill a contacts detail including its name, email address, and phone numbers using just one extender, but without modifying any provided functionality, so that our code be used with newer versions. Below is what it will look after populating that contact form.

contact

Continue reading

Disabling ASPX Controls on client side

To enable or disable .Net controls on client side use following scripts.

//To Disable
document.getElementById(element_client_id).setAttribute('disabled','true');

//To Enable
document.getElementById(element_client_id).removeAttribute('disabled');

Nearly all html rendered control would adher to this coding guide, but aspx checkbox has a span element wrapped up on it. To disable checkbox properly add a extra line as below.

document.getElementById(element_client_id).parentElement.removeAttribute('disabled');