Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get GET variable's value in javascript? [duplicate]

Tags:

javascript

get

Possible Duplicate:
Get query string values in JavaScript

how can i get the get variable in javascript?

i want to pass it in jquery function.

function updateTabs(){

            //var number=$_GET['number']; how can i do this?
        alert(number);
        $( "#tabs" ).tabs({ selected: number });

    }
like image 719
Nirali Joshi Avatar asked Aug 21 '12 06:08

Nirali Joshi


People also ask

How do you duplicate variables?

Right-click the variable that you want to duplicate and select Copy.

What is '$' in JavaScript?

The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.

Is JavaScript copy by reference or value?

Objects are assigned and copied by reference. In other words, a variable stores not the “object value”, but a “reference” (address in memory) for the value. So copying such a variable or passing it as a function argument copies that reference, not the object itself.


1 Answers

var $_GET = {};
if(document.location.toString().indexOf('?') !== -1) {
    var query = document.location
                   .toString()
                   // get the query string
                   .replace(/^.*?\?/, '')
                   // and remove any existing hash string (thanks, @vrijdenker)
                   .replace(/#.*$/, '')
                   .split('&');

    for(var i=0, l=query.length; i<l; i++) {
       var aux = decodeURIComponent(query[i]).split('=');
       $_GET[aux[0]] = aux[1];
    }
}
//get the 'index' query parameter
alert($_GET['index']);
like image 153
gion_13 Avatar answered Oct 19 '22 22:10

gion_13