javascript - How can i get the value of first query string in a URL -
To get query string value in a form field, using the following code:
& Lt; Script & gt; Var url = window.location.search; Url = url.replace ("? Id =", ''); // remove ? & Lt; / Script & gt; & Lt; Script & gt; Document.write ("input name = 'id' data-barriers = '@ required (group = [customer])' id = 'id' type '' type = 'text' value = '" + url + " '/ & Gt; "); & Lt; / Script & gt; If I [This is not a link] () it records the fields in the visit, but when more parameters are included then this field also records, I want only the first or a specific query string parameter in the form field To be added?
How to create a good small associative array outside of your query String parameters, like something:
var urlParams = []; Window.location.search.replace ("?", "") .split ("& amp;") ForEach (function (e, i) {var p = e.split ("="); urlParam [p [0]] = p [1];}); // We now have all the parameters - & gt; You can access it by name console.log (urlParams ["Id"]);
Comments
Post a Comment