Patrioticcow
Patrioticcow

Reputation: 27058

how to get a variable from a link using jquery and php?

i have this script on jsfiddle

basically this links:

 | <a id="mine_click" href="#?test=123">test</a> | 
 | <a id="mine_click" href="#?test=123">test1</a> | 
 | <a id="mine_click" href="#?test=123">test2</a> | 
 | <a id="mine_click" href="#?test=123">test3</a> | 

when i click on one of them i manage to change tabs but i want that test var to fallow and be displayed in the respective tab

any ideas?

Upvotes: 0

Views: 97

Answers (1)

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76910

You could use this function

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}

to get the variable and then print it.

fiddle here: http://jsfiddle.net/HysJ6/10/

Upvotes: 1

Related Questions