Skip to content

Instantly share code, notes, and snippets.

@RandomArray
Last active February 1, 2016 00:37
Show Gist options
  • Save RandomArray/2262563834024f0869d3 to your computer and use it in GitHub Desktop.
Save RandomArray/2262563834024f0869d3 to your computer and use it in GitHub Desktop.
Finds missing Name element pairs for input ID elements starting with a defined prefix. Just a shortcut to find missing pairs for when working with a large form.
var ids=[], names=[], notfound=[];
$("input[id^='myPrefix_'], textarea[id^='myPrefix_'], select[id^='myPrefix_']").each(function(){
ids.push(this.id);
// console.log(this.id);
});
$("input[name^='myPrefix_'], textarea[name^='myPrefix_'], select[name^='myPrefix_']").each(function(){
names.push(this.name);
// console.log(this.name);
});
$.each(ids, function(id,elm){
//var str = 'ELM: '+elm;
if($.inArray(elm,names) > -1){
//str += ' - FOUND NAME ELEMENT';
}else{
//str += ' - NAME ELEMENT NOT FOUND';
notfound.push(elm);
}
//console.log(str);
});
console.log('Matching "Name" elements for "ID" elements not found for these IDs:');
$.each(notfound, function(id,elm){
console.log(elm);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment