jQuery .attr() and .prop()

In jQuery, you have to be careful to use .attr() and .prop().

.attr() Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element.

.prop() Get the value of a property for the first element in the set of matched elements or set one or more properties for every matched element.

They are very similar, but not exactly same.

The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr()retrieves attributes.

For example, selectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, and defaultSelectedshould be retrieved and set with the .prop() method. Prior to jQuery 1.6, these properties were retrievable with the .attr()method, but this was not within the scope of attr. These do not have corresponding attributes and are only properties.

More details see
http://api.jquery.com/attr/
and
http://api.jquery.com/prop/

Advertisements
Posted in Computers and Internet, Laravel, Uncategorized | Leave a comment

Fix JSON decoding syntax error

I got a long JSON string from DB, and try to decode the string using json_decode() in PHP, I get null, the empty object. But when I tested it in a JSON pretty page http://jsonprettyprint.com/, everything looks good.

It’s no single/double-quotes in the JSON string, and encoding in UT8, and no escaped characters as well. But it’s always shows 4 as json_last_error() result , which means syntax error.

Then I tried to filter invisible characters from JSON string, like below

for ($i = 0; $i <= 31; ++$i) {
	$history = str_replace(chr($i), "", $history);
}
$history = str_replace(chr(127), "", $history);
$history = json_decode($history);

Then the issue solved.

Posted in Computers and Internet, Laravel, Lumen, Uncategorized, Yii | Leave a comment

Follow these 17 Proven Rules to Hire the Best Job Candidate

Author: Art Torres

Follow these 17 Proven Rules to Hire the Best Job Candidate

Follow these 17 Proven Rules to Hire the Best Job CandidateNo matter which industry you are in, it is critical to employ top performers. I often hear managers complain about a particular employee who is not performing. After talking for a couple of minutes, it usually becomes evident to me that the manager should not have hired this individual in the first place. Most of us agree that the hiring process is more an art than a science. What rules can we follow to increase the odds of hiring the best candidate, rather than the best job seeker? Below are a few guidelines that I strongly recommend and you can easily implement.

 

  1. Job Description

Spend some time writing a job description that clearly and accurately describes the job and the kind of person you are searching for. This will send the recruiters in the right direction and will allow job candidates to determine if they have a chance of getting the job. Indicate which skills are required and which are preferred. Start writing the job description based on your experience and then complement it with ideas from similar job descriptions from the online job boards. You can also get ideas from recruiters, peers and team members.

 

  1. In-Person Interview

Although you may want to have preliminary interviews over the phone, I strongly recommend in-person interviews for your short list of candidates. This way you can see their body language and how they present themselves. You want to hire applicants who show energy, passion, and camaraderie. I can almost see sparks coming out of the right candidate. Make sure you would feel comfortable working with this individual. On traditional firms, you expect the job candidate to dress in a neat and clean business attire and to have a professional demeanor. Many times, when I am in front of the right candidate, I feel a burning desire to hire him or her.

 

  1. Passion

Wouldn’t you agree that passion cannot be taught? Then you need to hire people who have a passion related to the job. The developers of the Google Sky app were software engineers, not astronomers. However, they were able to build this wonderful app, not just because they were great engineers, but also because they loved astronomy. Similarly, the engineers that designed the iPod and the iPhone were ardent for creating a cool, portable device to play lots of music, and do a plethora of awesome things. Enthusiasm is real and can be felt. It makes people glow and gives them a reason to do something worthy.

 

  1. Team Review

I do not like to do panel interviews because some candidates may feel intimidated and then do poorly in the interview. However, when the candidate comes to the office for the interview, I frequently schedule 5-10 minutes with a couple of people from the team and peers to briefly talk to the candidate and get first impressions. Sometimes one of these individuals may see something positive or negative about the candidate that you were not able to sense. For technical interviews, I also ask one of my gurus to interview the candidate.

 

  1. Skills, Experience, and Learning

You may not be able to get someone who knows on day one everything that the job requires. Therefore, you want to hire a person who knows the fundamentals of the job, is able to learn quickly any necessary knowledge, and has a mindset of continuous learning.

In technology companies and departments, don’t hire specialists for long term positions. The job will change over time. The technology will evolve and will transform the environment so swiftly that the particular skill will be no longer required.

 

  1. Test

Depending on the nature of the job, you might want to test the skills of the job candidate. The test can be done with a real or a hypothetical assignment. Present a typical business situation the candidate would encounter in this role and ask how he or she would handle it. You can also ask the job seeker to role-play a scenario or to deliver a presentation. Thomas Edison used to test his job candidates with ingenious questions. One time he held up a light bulb and asked the candidate how he could figure out how much water the bulb would hold. Most candidates used sophisticated gauges, measurements, and scientific calculations while a few of them simply filled the bulb with water and then poured it into a measurement cup. Sometimes the simplest solution is the best.

 

  1. Good Communication

It is important to hire someone with whom you can effectively communicate both verbally and in writing. You can test the verbal aspect during the interview by asking open-ended questions like these:

  • What did you like most and least about your previous working environment?
  • What are your major accomplishments?
  • What makes you get up in the morning and do what you do?
  • Why do you work?
  • Tell me about a time when you had a big failure.
  • Tell me about a time when you had a difficult discussion at work.

To find out his or her writing skills, prior to the interview ask the candidate to answer a few open questions relevant to the job. Add a couple of general questions, like:

  • What makes you the best candidate for the job?
  • Why do want to work for XYZ Corporation?

 

  1. Attitude

The in-person interview also helps you get a good idea of the candidate’s mindset and attitude. Look for a can-do attitude; somebody who gets the job done even when the assignment requires things like the following.

  • Working on projects or tasks that are not yet well-defined
  • Researching the subject
  • Asking questions to clarify the problem
  • Quickly learning new skills
  • Performing tedious steps
  • Asking for help
  • Dealing with difficult people
  • Working under pressure
  • Working under tight deadlines
  • Working longer hours

Look for someone who has a sense of urgency, is action-oriented, takes responsibility and is accountable for the task. Hire someone who is willing to challenge the status quo and think outside the box. Another important thing is the emotional IQ; properly managing his or her emotions, and effectively responding to the feelings and behaviors of others.

 

  1. Respect and Professionalism

Another thing that you can catch during the in-person interview is whether the candidate shows respect and professionalism. I remember a time when I came out late from a meeting, and as a result, I started the interview late. I apologized to the candidate, but for a few minutes, he kept bringing up his disapproval. Needless to say, I did not think I could work with that kind of person.

To get more insights on the candidate’s respect and professionalism, get input from the person at the front desk, the janitor, and other people who might have had a brief encounter with the candidate.

 

  1. True Character

It is normal for job candidates to put their best face during the interview. However, we are interested in seeing their real character. The best way to do this is to put them in a situation where they are under pressure. You can ask them an odd question that takes them by surprise. The answer to the question is not as important as how confidently the applicant answers the question. I once was asked this weird question, “What would you do if you were home and hear a knock on the door, and when you open the door, instead of a person, you see a big elephant?” Today you can also check the candidate’s social profiles and activities on LinkedIn, Facebook, Tweeter, and other platforms. Other techniques focus on putting the candidate in situations where they are completely relaxed, so they lower their guard and remove their mask. Some of these techniques include playing golf or just going to lunch or dinner.

 

  1. Diversity

You may be tempted to hire people like you. However, it is better for the company or group to hire people from different backgrounds (ethnicities, genders, education, regions, industries, etc.). This will bring different points of view and will augment creativity and innovation.

 

  1. Good Fit to the Company’s Culture

Make sure the candidate is a good fit for the company’s values and culture. For instance, a person who is used to work on start-up companies might have a hard time working on large, conservative, structured firms. You can ask the candidate what type of work environment he prefers. Similarly, if one of the key company values is innovation, make sure the applicant really embraces this value.

 

  1. Rigorous Selection

Be very selective. Instead of firing the bottom 10% from time to time, don’t hire poor performers. In many companies, firing poor performers is tough, tedious and long process. Therefore you should aim to hire people in the top 20%. Then even if you err in your interview process, you might still get a person in the top 40%.

 

  1. References and Background

Take your time in the hiring process even if a good friend strongly recommended the candidate. Trust, but verify. Check references and do a thorough background check. Failure to do this may result in embezzlements, stolen equipment, stolen customer identification, violence, and lawsuits.

 

  1. Contract-to-Hire

If you feel you made a mistake hiring someone, studies have shown that it is better to act quickly and let the person go. Unfortunately, many managers take too long to fire a person. In addition to the tedious paperwork, perhaps managers feel sorry about firing the employee, may have some fear, or they do not want to admit they made an honest mistake. A better option might be to get the person as a contractor with the company’s option to convert him or her to a full-time employee. This way you have a chance to evaluate the skills and personality for 3 or 6 months. If things do not work out, you can let the person go without any hard feelings.

 

  1. Quality vs. Speed

Never compromise taking enough time to hire the right candidate because of the urgency of filling a position. Otherwise, you may regret it badly. Remember that it is much harder to fire a poor performer than to hire the right candidate.

 

  1. Interviewing Skills

It is imperative to improve your interviewing skills continually, as effective hiring is fundamental to the success of the company. You might think that what attracts candidates to companies like Google are gourmet lunches, massages, espresso drinks, ping-pong tables, and casual dress. However, the main reason people come to these corporations is to work with great people. Therefore, by hiring great people, you will also attract more great people.

 

While there is no guarantee to hire the right candidate every time, the above principles will help you build a stronger team and have a pleasant working environment. Which techniques do you like the most? What other techniques do you recommend? Please share a comment below.

 

About the Author: Art Torres is an IT Quality Champion and Change Agent in the Finance and Insurance industries. Builds high-performance, customer-centric teams that enable swift completion of strategic projects with zero critical defects; resulting in higher profits and enhanced customer and employee satisfaction. Improves processes by developing and implementing policies and procedures, best practices, standards, and methodologies.

 

 

Posted in Human Resource Management | Leave a comment

css: make checked checkbox label bold

In many case, we want to highlight the checked checkbox label, so user know it’s checked without mistake. If you know CSS syntax, it becomes very easy:

In below case, we just want a certain check box (service, and network type checkbox)label changes:

.service-checkbox:checked + .checkbox-text,
.network-type-checkbox:checked + .checkbox-text {
   font-weight: bold;
}
Posted in Computers and Internet | Leave a comment

3 Autocomplete fields reuse same AJax call.

This is a typical customized request, which in one page, they want to enter same ticket number to search, and same time can search 3 fields, and do 3 different functions. So like below code showed, we reused same search function in autocomplete source.


$(document).ready(function(){
	var cache = {};
	$( "#lookup_ticketnum_1" ).autocomplete({
	  source: function(request, response){
		  search_msi(request, response)
		  },
  	  minLength: 3,  	  
    });
	$( "#lookup_ticketnum_2" ).autocomplete({
	  source: function(request, response){
		  search_msi(request, response)
		  },
  	  minLength: 3,  	  
    });
	$( "#lookup_ticketnum_3" ).autocomplete({
	  source: function(request, response){
		  search_msi(request, response)
		  },
  	  minLength: 3,  	  
    });
    function search_msi(request, response){
    	var term = request.term;
	    if ( term in cache ) {
	      response( cache[ term ] );
	      return;
	    }
	 
	    $.getJSON( "/matrix/ajax_search_msi.php", request, function( data, status, xhr ) {	    	
	      cache[ term ] = data;
	      response( data );
	    });
    }										
});

Posted in Computers and Internet | Leave a comment

2 steps Ajax calls in one autocomplete field

In our code, sometimes we need update drop down list depends on the content in another field entered. Below is an example to show how to use autocomplete field, after you selected the item, and triggered drop down list option selected.


$(document).ready(function(){
	var cache = {};
	$( "#lookup_ticketnum" ).autocomplete({
	  source: function( request, response ) {		  
	    var term = request.term;
	    if ( term in cache ) {
	      response( cache[ term ] );
	      return;
	    }
	 
	    $.getJSON( "/matrix/ajax_search_cm.php", request, function( data, status, xhr ) {	    	
	      cache[ term ] = data;
	      response( data );
	    });
	  },
  	  minLength: 3,
  	  select: function( event, ui ) {
  		//post ajax call to update cm group perform.
		$.ajax({
		 url:'/matrix/ajax_search_cm_group_perform.php',
	     type:'post',
	     data:{term:ui.item.value},
	     success: function( msg ) {
		    $('#entry_cm_group_perform').val(msg);
		    $($("#entry_cm_group_perform option")[msg]).attr('selected','selected');									    											    
	     },
         error: function() {
		 	alert("Something went wrong, please try again or contact a system administrator if the problem persists.");
         }
		});	  									  		  
      }    
    });										
});

Posted in Computers and Internet, Uncategorized | Leave a comment

Return the number of elements in the jQuery object.

Before jQuery 1.8, we like use .size() to get array element count. But .size() method is deprecated as of jQuery 1.8. It’s better to use .length property instead. The reason is the .length property is public, and does not have the overhead of a function call.

So if the object is string type, .length will return sting length, and if it’s array type, it will return count of array elements.

Posted in Computers and Internet | Leave a comment