Skip to content Skip to sidebar Skip to footer

Get Url Parameters With Jquery And Display Them Inside An Html Input Text Field

I been through dozens of articles on this on here and on Google but none of them seemed to have worked. I am trying to get parameters from the URL and display them inside an input

Solution 1:

Got it finally to work, updated a working script below to help anyone in the future:

functiongetQueryVariable(variable) {
                var query = window.location.search.substring(1);
                var parms = query.split('&');
                for (var i = 0; i < parms.length; i++) {
                    var pos = parms[i].indexOf('=');
                    if (pos > 0 && variable == parms[i].substring(0, pos)) {
                        return parms[i].substring(pos + 1);;
                    }
                }
                return"";
}

getQueryVariable("inputline1");

$(function () {
        $('#inputline1').val(getQueryVariable('inputline1'))
});

<inputtype="text"id="inputline1" />

The URL with parameter:

?inputline1=Sample

enter image description here

Post a Comment for "Get Url Parameters With Jquery And Display Them Inside An Html Input Text Field"