i have a link:
<a href="?
processor=<?php echo $value['processor']; ?>&
auth_code=<?php echo $value['auth_code']; ?>
" id="buttonDetails">View Detail</a>
and a function:
function getUrlVars(parsedUrl) {
var vars = {};
parsedUrl.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m, key, value) {
vars[key] = value;
});
return vars;
}
what i am doing is passing the link to this function;
var url = $('#buttonDetails').attr('href'); // "?processor=25&auth_code=12"
var first = getUrlVars(url);
alert (first );
this alert will give me [object Object]
any ideas what i am doing wrong?
edit: another way would be to:
var first = getUrlVars()["processor"];
alert(processor);
but this doesn't work as well
edit:
the links are created in a php loop:
foreach($test as Value){
// here is the link being created and the result is more links.
}
also i changed the id to class for the link.
and i'm doing:
$('.buttonDetails').each(function(){
var parsed = getUrlVars($(this).attr('href'));
console.log(parsed['processor']);
});
this will give me undefined
this console.log(parsed); will give me multiple objects with the data inside them. but when i try to get some specifics from inside the object i get undefined
why would this not work?
thanks again
alert(getUrlVars(url)["processor"])?firstis an object because you return one:var vars = {}. Alerting an object alerts[object Object]