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:
function getQueryVariable(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'))
});
<input type="text" id="inputline1" />
The URL with parameter:
?inputline1=Sample
Post a Comment for "Get URL Parameters With JQuery And Display Them Inside An HTML Input Text Field"