Monday 21 July 2014

Prevent the backspace key from going to the previous page in Ext JS application

If you have an app with just one view in ExtJS(Sencha), there is a possibility that the user will open the app in a browser that they have been using to cruise around the web and the user will likely use the backspace key in your app(say, inside a text box) then you should think about turning off the backspace == url -1 feature.

To disable 'Backspace' key use below JavaScript inside script tag of your html page:

document.onkeydown = KeyCheck;
function KeyCheck(e) {
if (!e) {
e = window.event;
}
var doPrevent = false;
if (e.keyCode === 8) {
var d = e.srcElement || e.target;
if ((d.tagName.toUpperCase() === 'INPUT' && (d.type.toUpperCase() === 'TEXT' || d.type.toUpperCase() === 'PASSWORD' || d.type.toUpperCase() === 'EMAIL' )) || d.tagName.toUpperCase() === 'TEXTAREA') {
doPrevent = d.readOnly || d.disabled;
} else {
doPrevent = true;
}
}
if (doPrevent) {
(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
}
}

Above code works well for IE and Chrome.


Saturday 21 June 2014

Evolution with Changing Times

Without the correct elucidation of how life evolved on this frabjous planet we have been able to ameliorate our existence. Crawling, walking and now flying high, we have travelled so far. Very long journey indeed from the Big bang to life, caves to glass-houses, worshiping nature to exploiting them, from sunlight to neon lights, giving life to cloning and last but not the least transmogrification of green jungles to cemented ones. Sometimes it's absolutely right to think that with the demise of pharaohs and withering pyramids, man has become the strongest drug for another man. Crossing centuries over centuries, human beings and the natural world have been on the collision course but still the human body is approximately two-third of water. Earth, water, air and fire still retain their power in front of all the deadly weapons and missile. The journey from evolution theory to living in peace and harmony, to cozy life and hi-tech automated world, we have upcoming theories like some forms of cosmic radiation can have a potent effect on our DNA and may precipitate periodic leaps in our evolution due to the induced genetic shifts.

There is no doubt that we are living in unstable times of great and unpredictable change.  We are seeing major cloud bursts, earthquakes, tsunami, volcanic activity, global warming and prolonged drought. Climate change is certainly upon us and of course there are many questions as to cause of this. But, the truth is that the world herself is changing.

"Infosys" can be termed as another beauteous byspel of evolution in modern IT world. With a small start from seven members and with an initial capital of US$ 250 it has grown to become a company of US$ 8.095 billion in 30 years with 1,58,000 employees. Technical evolution has changed the concept of physical labor to intellectual labor. Futurists have worked significantly on genetic engineering, nanotechnology, artificial intelligence and landing on mars and moon. Apt example of our technological dependence is for even writing this essay, we rely on search engines. Goal of evolutionary medicine now is to understand why people get sick, not simply how they get sick. “Why copy old life forms when we can now create new ones?”

We always need a driving force to work and perform better and our present time changing equation is helping our productivity to culminate. Our unceasing struggle to make life cozier, easier have enhanced our thinking and soared our expectations form younger generations. Computing on hands to cloud computing, we have accomplished a lot. Although our physical evolution obstructs us from connecting from distant places but with our super-evolved brain we can cross water, air and ice hindrances. Something that is about living in a more connected way, and moving away from separation, disharmony and greed. Over ages we have evolved from animals to nomads and then civilizing to become great rulers. Unfolding the hidden secrets of nature, our scientists have volunteered their whole life providing us with quantum physics and aerospace technologies, all because we want the best out of available. "Survival for the fittest" theory has incited the motivation to gain more and live more.

Everything haven’t changed completely yet, years ago Ram, Pandavs, Mughals, Hitler, Britishers fought for power, wealth and status on the cost of money and innocent lives and even today we live in a country under unstable and incompetent governance where our so called educated politicians and country shapers are never tired of being in scams. Life is cheaper than a bullet these days, “survival of the fittest” – is being construed to “kill or be killed”. What kind of evolution are we facing? Aggression, war, territorial possession, resource exploitation and separation from nature, deep wounds of poor given by the rich. We feel proud to say we live in harmony and brotherhood in spite of the fact that we believe in forming organizations to avoid wars and maintain balance among the countries rather believing in ourselves. Gurukuls' evolved too, children are now taught how to defeat their rivals in lieu of acquiring knowledge.

There is also an evolution in political will of our country. People from various background – including corporates, actors, army men, chai-wala, sehjada and aam-admi do not hesitate to express their views for the political reform. We have witnessed record breaking enrolment in the voter list across our country this year. Is this the sign of great success this election will bring or, huge amount of despair and frustration post-election?

In present scenario, we have the issue of the petrol prices.  What is going on with the price of a litre of petrol?  Are the oil companies ripping us off?  Or, do we have any oil reserve left?  What is this talk of “peak oil” and a rapidly approaching scarcity of all fossil fuels and mined energy sources – including coal, uranium?

What about global economic crisis?  What is going on with our financial system?  Has the over-speculation of the corporations in United States caught up with us all and tipped the world into another Great Misery?

Lot more questions are being asked. But, the point is – we need to be very careful.  Because maybe, just maybe, these things are not a sign of chaos but are actually showing us that we are getting it right – in a long run. These crises could be an opportunity for real change and positive growth – both individually and as a planet.

At the end what exactly we infer, perhaps we are evolving from Homo-sapiens (the pondering human) to Homo-spiritus (the awakening spiritual human). The massive and accelerating changes going on in the world around us are in fact the fuel for this change. Surely this is a very positive thing. A great time to be alive! As we begin to ride the wave into human redesign, the destination is still largely unknown but the opportunities are almost limitless. . There is no limit to what we can achieve tomorrow and a probability that our next generation would have a quite different definition of "evolution".

The great gift we have with us is – our reasons and our consciousness. Use them well!

Thursday 17 April 2014

Open an external application using IE browser

We can launch a new application using ActiveXObject of the Internet Explorer. Below is the sample code -

<!DOCTYPE html>
<html>
<body>

<p>Click the button to open a new application window.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
 w = new ActiveXObject("WScript.Shell");
          w.run('chrome.exe');
          return true;}
</script>

</body>
</html>

Wednesday 5 February 2014

HTML text box to allow numbers only

We generally encounter the need of functionality where text boxes need to be filled with numbers only(may be for security/validation). We have a easy JavaScript solution for this -

<!DOCTYPE html>
<html>
<script>
 function CheckNumeric(event)
{
    var key = window.event ? event.keyCode : event.which;
    //Check for backspace, delete, left arrow and right arrow keys
    if (event.keyCode == 8  || event.keyCode == 46 || event.keyCode == 37 || event.keyCode == 39)
    {
        return true;
    }
    //All other keys excluding numeric keys
    else if ( key < 48 || key > 57 )
    {
        return false;
    }
    else return true; //Numeric keys from 0 to 9
};
</script>


<body>
<input type="text" id="txtSample" name="txtSample" onkeypress="return CheckNumeric(event)" />
</body>


</html>


Alternatively, there is one more method to use input types as numbers only. Here you can also set restrictions on what numbers are accepted. Its HTML5 way -
Cons: It is not supported through all browsers and their versions.

<!DOCTYPE html>
<html>
<body>

<form action="demo_form.asp">
  Quantity (between 1 and 5): <input type="number" name="quantity" min="1" max="5">
  <input type="submit">
</form>

<p><b>Note:</b> type="number" is not supported in Internet Explorer 9 and earlier versions.</p>

</body>
</html>