Friday, December 6, 2013

Focusing on last textfield in twitter bootstrap modal form when pressing tab

I observed that in  Twitter bootstrap modal form, tab key was not focusing on the last element when the focus in  on second last element and tab key is pressed.

Found this workaround to resolve

 $('#billingInfo').keydown(function(e){
  if($('#buyerPincode').is(":focus") && (e.which || e.keyCode) == 9){
    e.preventDefault();
    $('#buyerPhoneNumber').focus();
  }

#billingInfo -> ID of the twitter bootstrap modal form

#buyerPincode-> ID of second last element

#buyerPhoneNumber->ID of last element in the form.

keyCode=>9 is the keycode for tab key

Thursday, December 5, 2013

Focusing on the textbox and setting the cursor at the end of the prepopulated text

Here's a simple way to focus the textbox and set the cursor at the end of prepopulated text box:

This code will find the first input visible element in first form in DOM and set the cursor at the end of the text box. This stores the value of the textbox in temp string, resets it and reloads the text.

jQuery(document).ready(function(){

     var el=  jQuery('form:first :input:visible:enabled:first');
     el.focus();
     tmpStr= el.val();
     el.val('');
     el.val(tmpStr);

}};
Autofocusing on text box inside a modal dialog in Twitter bootstrap

I stumbled upon a problem today figuring out why .focus event is not working for a textbox inside a modal dialog while using twitter bootstrap until I found that .focus won't work for the elements outside the DOM when the page is first loaded.

The event in the Twitter bootstrap documentation named shown.bs.modal works perfectly well. Here is the sample of suppose I want to autofocus on email text field in the dialog(myModal is the id for the dialog, and exampleInputEmail2 is the id of the textbox


jQuery(document).ready(function(){
$('#myModal').on('shown.bs.modal', function () {
  $('#exampleInputEmail2').focus();
 });
});

Thursday, May 31, 2012

Vishwanathan Anand- greatest Indian sportsman?

Feels refreshing to hear  in the sports bulletin of the news channels dominated by IPL few weeks ago,the scintillating news of India's greatest sportsman ever(debatable?) winning the world championship 5th time which is no mean achievement. So it has again popped up the dormant question - Is he the better contender of Bharat Ratna than nation's most revered and followed sports person -Sachin Tendulkar?

Chess, however boring it may seem to watch is the game of intangible mental strength. Anand has won the world championship which is played by 185 countries which makes this achievement unique.Anand has virtually broken the monopoly of Russia in the world chess circuit and established India among one of the top chess playing nations with his numerous titles.Above all, he is a thorough gentleman in the sporting circle around the world with his humble and down to earth nature and has inspired the nation to take up this greatest game of board seriously.


Though this doesn't undermine what Sachin has achieved over the years, its high time that this most underrated sports person gets his due along with the likes of Sachin Tendulkar and Dhyanchand.The government should consider adding Vishwanathan Anand to the list of candidates for Bharat Ratna

Wednesday, July 20, 2011

How to check what maximum power of prime number can divide a factorial number exactly?

If the number by which the factorial number has to be divided is a prime number i.e p and the maximum power of p is n. Let the factorial no. is N

We can check the maximum power of p by

n= [N/p] + [N/p2] + [N/p3] + ........................


Let 72! be the number and we have to find maximum power of 5 which can divide 72! exactly:

Therefore,

n=[72/5] + [72/25] = 14 + 2 = 16.

Monday, July 18, 2011

How to find if the no. is prime or not

An easy way of finding if the no. is prime or not can be summarized in the following steps:

1)If the no. ends with 0,2,4,5,6,8 ; it is not prime.

2)Find the square root of the number and round it of to a lower integer. Find if the resultant number is divisible by prime numbers below it. If it is not, it is a prime number and if it is, it is a composite number.


Eg: If we want to check for 181. Square root 181 lies between 13 and 14. Therefore rounding of to lower integer, the resulting number is 13. Since 13 is not divisible by 2,3,5,7,11; we conclude that 181 is a prime number.

Try for higher numbers as well, this method works.

Saturday, September 15, 2007

Touching life story.....

Touching life story..... A young man was getting ready to graduate college. For many months he had admired a beautiful sports car in a dealer's showroom, and knowing his father could well afford it, he told him that was all he wanted. As Graduation Day approached, the young man awaited signs that his father had purchased the car. Finally, on the morning of his graduation his father called him into his private study. His father told him how proud he was to have such a fine son, and told him how much he loved him. He handed his son a beautiful wrapped gift box. Curious, but somewhat disappointed the young man opened the box and found a lovely, leather-bound Bible. Angrily, he raised his voice at his father and said, "With all your money you give me a Bible?" and stormed out of the house, leaving the holy book. Many years passed and the young man was very successful in business. He had a beautiful home and wonderful family, but realized his father was very old, and thought perhaps he should go to him. He had not seen him since that graduation day. Before he could make arrangements, he received a telegram telling him his father had passed away, and willed all of his possessions to his son. He needed to come home immediately and take care things. When he arrived at his father's house, sudden sadness and regret filled his heart. He began to search his father's important papers and saw the still new Bible, just as he had left it years ago. With tears, he opened the Bible and began to turn the pages. As he read those words, a car key dropped from an envelope taped behind the Bible. It had a tag with the dealer's name, the same dealer who had the sports car he had desired. On the tag was the date of his graduation, and the words...PAID IN FULL. How many times do we miss God's blessings because they are not packaged as we expected?