Created
October 27, 2011 12:23
-
-
Save chernomyrdin/1319414 to your computer and use it in GitHub Desktop.
Parse query_string and fill form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pqsaff () { | |
this.vars = (window.location.search.length > 1) ? | |
window.location.search.substring(1).split("&") : | |
[]; | |
} | |
pqsaff.prototype = { | |
param: function (s) { | |
var p = s.split("="); | |
this.name = p.shift(); | |
this.value = unescape(p.join("=")); | |
}, | |
fill: function (name,xlate) { | |
var f = document.forms[name]; | |
if (f && this.vars.length) { | |
for (var i = 0; i < this.vars.length; i++) { | |
var v = new this.param( this.vars[i] ); | |
var field = f.elements[xlate ? xlate[v.name] : v.name]; | |
if (field) { | |
field.value = v.value; | |
} | |
} | |
} | |
return f; | |
} | |
}; | |
/* | |
* Usage: | |
* | |
* (new pqsaff()).fill("theFormName"); | |
* (new pqsaff()).fill("theFormName",{email:"mail",firstName:"fn",lastName:"ln"}); | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment