Ok this might have asked several times I have checked all solutions but cannot get my head around it.. Please help me to figure this one out.
- Run each loop on form ID and get all input fields which have a specific name.
- Access the result from outside the loop function.
HTML Code is
<input type="radio" name="position" id="left">
<input type="radio" name="position" id="center">
<input type="radio" name="position" id="right">
Below is the loop code.
var inputType = $('#form-main input[name="position"]').each(function(){
inputType = $(this).attr('id');
console.log('Data Types are : ' + inputType);
});
When console.log is placed inside the loop or function I get [left, center, right ]
How can I access this result outside the function or the loop. When console.log is placed outside the loop or function I get [object object]