Thursday, June 8, 2017

Dynamically create input name and id via associated label text

var groupA = "";
$('label').each(function(index, item) {
var a = $(this).text();
a = a.replace(/\W/g, '');
a = a.replace(/\s/g, '');
a = a.toLowerCase();
groupA = $(this).attr('group');
$('input:text').each(function(index,item) {
if ($(this).attr('group') == groupA) {
$(this).attr('name', a + $(this).attr('typeB') );
$(this).attr('id', a + $(this).attr('typeB') );
}
});
});