I want to pre - populate text box (and gray it out for editing) with a URL parameter value inside a jquery snippet of code:
The Jquery code:
jQuery(document).ready( function () {
$("#append").click( function(e) {
e.preventDefault();
$(".inc").append('<div class="controls">\
<input class="form-control" type="text" name="textbox" placeholder="email">\
<input class="form-control" type="text" name="text" placeholder="@domain">\
<a href="#" class="remove_this btn btn-danger">remove</a>\
<br>\
<br>\
</div>');
return false;
});
jQuery(document).on('click', '.remove_this', function() {
jQuery(this).parent().remove();
return false;
});
$("input[type=submit]").click(function(e) {
e.preventDefault();
$(this).next("[name=textbox]")
.val(
$.map($(".inc :text"), function(el) {
return el.value
}).join(",\n")
)
})
});
The specific text field i want to prepopulate :
<input class="form-control" type="text" name="domain" placeholder="@domain">\
The function i have for obtaining the said parameter value:
function GetURLParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}