javascript - Print Variable To Input Field Element -
hi have input , wondering how can print value based on it's id?
<input name="field[34]" id="field34" class="input-text required-entry validate-field-hint-34 webforms-fields-hint" style="" value="e.g: nx15 nam" onfocus="if (this.value == 'e.g: nx15 nam') {this.value = ''; $(this).removeclassname('webforms-fields-hint');}" onblur="if (this.value == '') {this.value = 'e.g: nx15 nam'; $(this).addclassname('webforms-fields-hint');}" type="text">
i have script takes value of url , turns variable. want print variable input field.
var querystring = function () { // function anonymous, executed , // return value assigned querystring! var query_string = {}; var query = window.location.search.substring(1); var vars = query.split("&"); (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); // if first entry name if (typeof query_string[pair[0]] === "undefined") { query_string[pair[0]] = decodeuricomponent(pair[1]); // if second entry name } else if (typeof query_string[pair[0]] === "string") { var arr = [ query_string[pair[0]],decodeuricomponent(pair[1]) ]; query_string[pair[0]] = arr; // if third or later entry name } else { query_string[pair[0]].push(decodeuricomponent(pair[1])); } } return query_string; }();
any idea how can this?
thanks, nick
that simple, substitute below placeholder values actual values.
document.getelementbyid("yourelementid").value = yourvariablename;
make sure dom
loaded before trying this.
edit 1
document.addeventlistener("domcontentloaded", function() { document.getelementbyid("yourelementid").value = yourvariablename; }, false);
Comments
Post a Comment