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
Oh boy, this would be a one liner with jQuery:
$(':input:not(:button)', div).val([])
Without jQuery you've got to account for <select>
fields, text fields, password fields and radio/checkbox fields:
function clearFields(container) {
var selects = container.getElementsByTagName('select');
for(var i=0, len=selects.length; i < len; i++) {
selects[i].selectedIndex = -1;
}
var fields = container.getElementsByTagName('input');
for(var i=0, len=fields.length; i < len; i++) {
var field = fields[i];
switch(field.type)
{
case 'radio':
case 'checkbox':
field.checked = false;
break;
case 'text':
case 'password':
case 'hidden':
field.value = ''
}
}
var fields = container.getElementsByTagName('textarea');
for(var i=0, len=fields.length; i < len; i++) {
fields[i].value = ''
}
}
$('#div_id input[type=textbox], #div_id select, #div_id textarea').val('');
$('#div_id input[type=radio], #div_id input[type=checkbox]').prop('checked', false);
for jquery.