Today’s Learning: Conditional validations using jquery

January 15, 2013 1 comment

Generally we have validations set in validation rules object. This way we can set static rules for a field. What if we have to validate a field depending upon input of other field (conditional validation).

For example: if area-code is entered, make phone field mandatory etc.

Here is a javascript code which adds validation rules according to the condition:

//The validator object

var validatorObject = {

rules: {

‘first_field_id’: {    

required: false,

minlength: 1,

maxlength: 50


‘second_field_id’: {         

required: false,

minlength: 1,

maxlength: 25





          var newRule = {

                   required: {

                             depends: function(element) {

                              //check if first field is set        

if ($(this).val() != ”) {

                                                return true;


                                                return false;








Now validate the form


Categories: Java Script

Today’s Learning: binding more than one events in jquery

November 21, 2012 Leave a comment

To call a custom event handler when an event fires, we can use “.bind()” jquery method as described below :

$(‘#foo’).bind(‘click’, function(){
//do something on click event fire

To bind more than one events to one element, we can include each event in “.bind()” method separated by space :

$(‘#foo’).bind(‘click mouseover keyup …’, function(){
//do something on event fire

To bind multiple event handlers to one element (As of jQuery 1.4) :

focusout: function() {
// do something on focusout
mouseover: function() {
// do something on mouseover
click: function() {
// do something on click

Categories: Java Script Tags: ,

The Top 5 Internet Destinations in 2011

December 29, 2011 Leave a comment

There was a tough fight between internet search giant Google and the social networking giant Facebook to be at the top internet destinations. According to the research done by market researcher Nielsen, here are the lists of top 5  internent destinations of 2011:

1- Top 5 Web Brands

Microsoft and Apple take 6th and 9th positions respectively

2- Top 5 Social Networks and Blogs

LinkedIn and Google+ get 6th and 8th positions respectively

3- Top 5 Destinations for Video

Categories: News Tags:

The Samsung Galaxy Tab Line Steps Down

July 11, 2011 Leave a comment
Categories: News

PHP Editor Support for .module and .inc Files in Eclipse

July 1, 2011 1 comment

I have been using eclise from and found very helpful editor to write the PHP programs. It provides in-buit support for developing PHP programs. While working on a Drupal project, I encounterd that Drupal uses PHP code (specially in modules) written in files having .module and .inc extensions. Ecplise doesn’t provide the built-in support for these extensions. So, when you open these files, the will appear as simple text files with no PHP editor support.

I did some R&D and found one solution for this problem. We can add the content types in eclise to solve this problem. Here are the steps:

Step -1: Go to Window -> Preferences

Step -2: Click on General -> Content Types. Select “PHP Content Type”, then click “Add” button. Write “*.module” or “*.inc” in Content Type text box in new window and then click “OK” button.

Step -3: Click on Editors -> File Associatons. Click on first “Add” button and type “*.module” or “*.inc” in File Type text box in new window and then click OK

Step -> 4: Then click “OK” button to close the Preferences window and restart eclipse.

Now when you will open any .module or .inc files, the editor will have PHP support.

Categories: Technical Tags: , ,

A Request to Mayawati

September 23, 2010 Leave a comment

Dear Mayawati,

Respectfully we beg to say that please be human and save some money for disaster managment instead of just spending hard earned money in making statues of yours and your beloved elephants. Now it is too late as people are dying in western UP without food and homes affected by flood and you are asking Rs.2000cr aid from center. Shame on you.


Citizens of UP

Categories: Myidea

Back To Life

December 28, 2009 4 comments

Yes, I am back to life. Before starting job in IT company, I was fit and leading very healthy life. After that my lifestyle changed. My daily schedule included coming to office by bike and sit in the office for more than 9hrs
and going back to room, have dinner and sleep. This schedule depressed my physical activities very much but not my food intake. consequently, I started accumulating fat. I never realized that the fat I was gaining was slowly affecting my thinking and attitude. My attitude towards my relationships, life, and future prospects started getting dull. Consequently my work performance started dipping. I never felt fresh and enthusiastic in daily activities even after taking full rest.

Once I got one chain mail having words of Infosys chief Narayan Murthi addressed to the IT techies. He said “life is not just the office and work. Life means a lot. Manage your time so that no need to sit extra time in office. After office explore some new activities. This will make u fresh.”

Getting inspired with this, I thought why not start fighting with my fat. I joined a gym and started spending at least 1 hr everyday there. The initial days were very difficult and full of tiredness. But slowly I started getting my energy and exuberance back in daily routine. My work performance got better with positive attitude towards life. I lost around 4Kg weight within 1 month. I can’t express how good it feels to stand in front of the mirror and see myself coming in shape again. I would like to list some of the improvements in daily routine:

1- Now I don’t feel like sleeping 15 min more in morning and open eyes with full freshness (be at office on time).
2- Now I don’t suffer the sleepless (or less sleep) nights and have sound sleep because of being tired physically.
3- Less yawning in office and meetings (my biggest achievement).
4- Better utilized my free time (rather than just watching TV).

5- Started using my older favourite jeans (another achievement).
6- No time to think negative (empty mind is devil’s home).
7- Wrap up my work within office time (improves my time management).

Now I am planning to join swimming classes on weekends. I found my life back with this idea, you never know which one brings yours back. So keep exploring your hobbies. This really works.

Categories: Myidea Tags:

Pranav Mistry: Master of SixthSense Technology

November 19, 2009 1 comment
Pranav Mistry demoed some sixth sense technology enabled tools TEDIndia. He showed that how a physical device can interact with the world of data and information. The interesting part is that he started working on his concept tools from using the motion sensors of an ordinary computer mouse.
With the full development and the implementation of his concept devices one can:
* watch the news as TV news printed on news paper,
* find more details of any physical object just by taking them in one’s hands,
* take pictures just by making frames using one’s fingers,
* pick any picture or block of data like a physical object and drop them on your computer screen or any other paper to modify them and a lot more.
Microsoft’s “Surface” is also based on multi-touch and gesture recognition, but has some limitations. The concept tools presented by Pranav are really  awesome and brilliant. The constructive use of this technology will bring a revolution in the future world.
I think the best use of this technology to help the physically challenged people. Just imagine how helpful it would be if we can make:
* Sixth sense enabled paper helping the deaf to display what others say,
* Sixth sense enabled earphones which tell a blind about an object name, type, size and distance,
* A speaking device which plays the dialogs which a dumb want to say and a lot more.
I really appreciate Pranav to come up with this brilliant idea.
Categories: Technical Tags: ,

Basic Questions on PHP Part2

November 16, 2009 2 comments
After getting a very good response on my earlier compilation “Basic Questions on PHP “, I am back with a new compilation of basic PHP questions on arrays.
1- How to check if a value exists in an array?
Ans Use in_array() function for this.
$sample = array(“banana”,”apple”,”pear”,”banana”);
$newvalue = “pear”;
if (in_array($newvalue,$sample)) { echo “$newvalue is already in the array!”; }
2- How to create an array of consecutive numbers and array of alphabets?
$arr_of_numbers = range(1,10);//$arr_of_numbers = array(1,2,3,4,5,6,7,8,9,10)
$arr_of_letters = range(a,m); //$arr_of_letters = array(a,b,c,d,e,f,g,h,i,j,k,l,m)
3- How to reset an array?
Ans: The reset() function does this and returns the first element of the array.
$sample = array(‘itm1′,’itm2′,’itm3′,’itm4’);
$first = reset($sample);
echo $first; //itm1
4- How to count the frequency a value appears in an array?
Ans: array_count_values() function does this operation. It returns an associative array with values as keys and their fequencies as values.
$sample_arr = array(1,0,1,2,0,2,2,2,3,4,2,5,2,3,5,3,1,5);
$most_popular = array_count_values($sample_arr);
output: Array(
[1] => 3
[0] => 2
[2] => 6
[3] => 3
[4] => 1
[5] => 3
5- How to remove last element of an array?
Ans: array_pop() function does this.
$sample = array(“One”,”Two”,”Three”,”Four”,”Five”,”Six”);
$last = array_pop($sample);
echo “last element is “.$last; //last element is Six…
6- How to sort an array with alphanumeric values?
Ans: natsort() function will do this.
$sample = array(“1.gif”,”2.png”,”20.jpg”,”10.gif”);
Array (
[0] => 1.gif
[1] => 2.png
[3] => 10.gif
[2] => 20.jpg
7- How to change an array into string?
Ans: We can achieve this using “implode()” function.
$sample = array(“I”,”love”,”PHP”);
$sample_to_string = implode(” “, $sample);
echo “$sample_to_string”;//I love PHP
8- How to remove duplicate values from an array?
Ans: The array_unique() function will do this.
$sample = array(“pear”,”apple”,”pear”,”banana”);
$sample_to_unique = array_unique($sample);
[0] => pear
[1] => apple
[2] => banana
9- How to interchange key to values and visa versa of an array?
Ans: We can do this using array_flip() function.
$sample = array(“John”,”Alice”,”Boby”);
$flipped = array_flip($sample);
[0] => John
[1] => Alice
[2] => Boby
[John] => 0
[Alice] => 1
[Boby] => 2
10- How to add an element at the begining of an array?
Ans: The array_unshift() does this. This function returns the number of elements in the array after additions of the new element.
$sample = array(2,3,4,5,6);
$no_sample = array_unshift($sample,1);
echo “Number of elements: $no_sample \n\n”;
Number of elements: 10
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
Hope these questions will help the PHP folks. I will come soon with some new PHP stuff.
Categories: PHP Tags: , ,

I Love Firefox

November 13, 2009 Leave a comment
Nov 09th is the birthday of Firefox and this year it has completed 5 years. I can say these five years firefox has  shown continuous growth to success and popularity. Being a web developer I can bet that firefox is the best internet
browser among others. Most of the open source web developers prefer to use this as default web browser. I can recall that I used IE only once just to download firefox on my personal computer. Our most of the development time goes in fixing design related bugs on IE and this is really frustrating.
Many many thanks to the firefox development community.
Categories: Myidea