Get url parameters and their values using javascript

In this programming tutorial, we will learn how to get url parameters and their values using javascript. Recently, while working on a project, i needed to get parameter values from url string of the current web page. So let's have a look over how i made this happen.

Get url parameters and their values using javascript

// Read the page's GET url variables and return them as an associative array.
function getUrlParametersVals()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
Now let's have a look over how to call this getUrlParametersVals() function.

This function returns an associative array with url parameters and their values. For example, let's suppose we have the following URL

http://www.yourwebsitecom/contact.php?name=Adeel&country=Pakistan 

Calling getUrlParametersVals() function would return you the following array:
{
    "name"    : "Adeel",
    "country" : "Pakistan"
}
To get the value of first parameter you will do this
var myName = getUrlParametersVals()["name"];
To get the value of second parameter you will do the same
var myCountry = getUrlParametersVals()["country"];
So that's it. 


I hope you will find this tutorial very informative. 

I love your feedback.
Read more...

New iPad joystick promises more accurate gaming actions

Now iPad and other tablets have got their own joystick. Logitech has leapt into the gadget-accessory fray with a tool it claims will help you to remove a poorly aimed rocket blast.

The Logitech Joystick is clearly focus to make the gaming experience on the iPad closer to what gamers enjoy on more dedicated gaming devices.

"No one likes to lose a point or go down to defeat because their thumb misses the control area," the company says on its Website for the $19.99 gadget.."The Logitech Joystick provides you a thumb-stick style game controller for iPad that you can use with just about any game with an on-screen joystick or d-pad."

This joystick attaches to the iPad screen with suction cups, allowing the user move it around depending on the game. A coiled spring keeps the stick centered.

The site lists 32 games that the joystick is currently compatible with. That list is heavily weighted toward sports games and shooters that made a splash on traditional gaming consoles before being reworked for the iPad.

Among them: "Madden NFL 11," "Call of Duty World at War: Zombies," "FIFA '11," "Prince of Persia: Warrior Within" and "Resident Evil 4."

More casual titles like "Cut the Rope" and "Fruit Ninjas" are nowhere to be seen, a likely nod to the fact that many of those games require swiping at multiple spots instead of being focused largely in one place.

The Wall Street Journal notes that the product is part of an increased focus on tablet accessories by Logitech, which has struggled somewhat as Apple's ascendance has hurt its PC-accessory trade.

CNET noted that the joystick, which is available for pre-order and set to ship in September, looks similar to the already available Fling Joystick, which performs a similar function and is offered at the same price. Source by CNN
Read more...

Get last character of a string in javascript

In this programming tutorials you will learn how to get last character of a string in javascript. Javascript is a very powerful client side language and there are various methods in it to get last character of a string. So let's have a look over the code snippet given below.
Get last character of a string in javascript
Method 1
Method 2 So that's it. I hope you will find this tutorial very handy. Happy Coding, Keep Coding. I love your feedback.
Read more...

Remove first character of a string in javascript

In this programming tutorial we will learn how to remove first character of a string in javascript. I have already written a tutorial that demonstrates how to remove last character of a string in javascript. Removing first character of a string can be easily done by using some built-in javascript functions. I will discuss two methods to achieve the task. Let's have a look over the examples given below.
Remove first character of a string in javascript
Method 1
var myString="Hello World!";
// newString will contain 'ello World!'
var newString=myString.substring(1);
Method 2
var myString="Hello World!";
// newString will contain 'ello World!'
var newString=myString.slice(1,myString.length);
So that's it. I hope you will find this tutorial very handy.
I love your feedback.
Read more...

Remove last character of a string in javascript

In this programming tutorial we will learn how to remove last character of a string in javascript. It can be easily done by using some built-in javascript functions. I will discuss two methods to achieve the goal. Let's have a look over the code snippet given below.
Remove last character of a string in javascript
Method 1
var myString="Hello World!";
// newString will contain Hello World!
var newString = myString.substring(0, myString.length-1);
In the above method, we have a string 'hello world!', the newString subtract the string, take the character range from the first to the second last character of a string, and we will get the new string newString 'hello world'.
Method 2
var myString="Hello World!";
var newString = myString.slice(0, -1);// newString contains Hello World!
In the above method we are using the javascript built-in function slice(). Using slice() we can extract any part of the string . This function needs two parameters p1 and p2. Value of p1 indicates the starting position of the sub string and value of p2 gives the length of the sub string. The first position (left side) of the main string is known as 0 position of the string. Say for example we want sub string of length 5 characters from left side of the main string so here we have to use slice(0,5) . In our example we don't want to get the last character of a string that's why we use slice(0,-1). If we want to remove last two characters then definitely we will use slice(0,-2).

So that's it. This is the way to remove last character of a string in javascript.
I love your feedback.
Read more...