Is there a simple way to iterate over the child elements in an element, say a div, and if they are any sort of input (radio, select, text, hidden...) clear their v
This is an old post but someone can see it.
function clearFields(divElement) {
var ancestor = document.getElementById(divElement),
descendents = ancestor.getElementsByTagName('*');
var i, e, d;
for (i = 0; i < descendents.length; ++i) {
if (descendents[i].tagName.toLowerCase() == 'input'){
switch (descendents[i].type){
case 'text':
case 'password':
case 'color':
case 'date':
case 'email':
case 'month':
case 'number':
case 'range':
case 'search':
case 'tel':
case 'time':
case 'url':
case 'week':
descendents[i].value = '';
break;
case 'radio':
case 'checkbox':
descendents[i].checked = false;
}
}
else if (descendents[i].tagName.toLowerCase() == 'select'){
descendents[i].selectedIndex = 0;
}
}
}
and to use it:
clearFields ('divName');
Of course you can add more elements to rest it