Currently, I am attempting to use JavaScript to retrieve the input elements within a form. My goal is to categorize them by placing them into an array based on their name attribute. Can someone offer assistance with this task?
function extractFields(formName, attr){
var form=document.getElementById(formName);
var fields=form.getElementsByTagName('input');
var fieldCount=fields.length-1;
var fieldNames=[];
for(var a in fieldCount){
fieldNames[a]=fields[a].getAttribute(attr)
}
return fieldNames[1];
}