Friday, 9 July 2010

Get Query String Using Javascript

Weeks ago I needed to get queystring parameters using JavaScript. I found a function called querySt(), this function is quite useful but I added an extra line that returns the string "undefined" in the case that the requested parameter does not exists in the querystring. My final code is:

function querySt(ji) {
    hu =;
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
    return "undefined";

No comments:

Post a Comment