Thank you for visiting my site!

Home / Customization with JavaScript, jQuery, HTML, CSS, SASS / Get the Query string and value passed in URL

Get the Query string and value passed in URL

//-------------------------------------------------
// Get the Query string and value passed in URL after the & sign "HiddenCapability=6"
//     http://siteurl&HiddenCapability=6
//------------------------------------------------

// Function to separate each url search string parameters
function getQueryParameters(){
    qObj = {};
    var urlSearch = window.location.search;
    //console.log(urlSearch);
    if(urlSearch.length>0){
        var qpart = urlSearch.substring(1).split('&');
        console.log('qpart ' + qpart);
        $.each(qpart,function(i,item){
            var splitAgain = item.split('=');
            console.log('splitAgain ' + splitAgain);
            qObj[splitAgain[0]] = splitAgain[1];
        });
    }
    //console.log(qObj.HiddenCapability);
    console.log('qObj ' + qObj);
    return qObj;
    //return qObj.HiddenCapability;
}

//Set the values for HiddenCapability out of object qObj.HiddenCapability=6
//Set the value of Source

var setAccessLevel = getQueryParameters().HiddenCapability;
var setSource = getQueryParameters().Source;

//console.log('setAccessLevel ' + setAccessLevel);
//console.log('setSource ' + setSource);

// Set the value of dropdown with the querystring value
$("select[title='Access to capability']").val(setAccessLevel);

ADD YOUR COMMENT