i will like to get a url value upon onclick. like this:
www.google.com/myfile.php?id=123
i want to get id and its value.
thanks
i will like to get a url value upon onclick. like this:
www.google.com/myfile.php?id=123
i want to get id and its value.
thanks
After reading the comments, it looks like you want a way to get the query string off a url, but not the current url.
function getParameters(url){
var query = url.substr(url.lastIndexOf('?'));
// If there was no parameters return an empty object
if(query.length <= 1)
return {};
// Strip the ?
query = query.substr(1);
// Split into indivitual parameters
var parts = query.split('&');
var parameters = {};
for(var i = 0; i < parts.length; i++) {
// Split key and value
var keyValue = parts[i].split('=');
parameters[keyValue[0]] = keyValue[1] || '';
}
return parameters;
}
function alertId(a){
var parameters = getParameters(a.href);
alert(parameters.id);
}
//onclick="alertId(this); return false;"