Yo haría algo así, no lo probé porque ando sin tiempo, lo hice muy, muy, rápido, pero espero se entienda la ídea y se acomode, ojo tomé arbitraríamente que si los valores de checkboxs, radios y combos no tienen valores asignados, igual se toma como no ingresado, puede pasar que no tengan valor pero si esten si hayan sido operados, así que ojo ahí:
Código Javascript
:
Ver originalfunction allFill(id, selectDefaultNeeded /* üse default value of selects as is not filled form */, selectFirstDefault /* in select the fist option is consider default */){
var form = document.getElementById(id);
var inputs = form.getElementsByTagName("input");
var radios = new Array(); //neccessary for radios checks
for(var k=0;k<inputs.length;k++){ //check for inputs
var input = inputs[k];
var type = input.getAttribute("type");
if(input.value == ""){ return false }
if(type == "checkbox" && !input[k].checked){ return false; }//for checkbox
if(type == "radio"){ //for radios, this is quitely complicated
var name = input.getAttribute("name"); //getting the radio name group
var passthru = false; //aux to se if the radio groud will pass the exam
if(radios.indexOf(name) == -1){ //if the groups is not checked yet
var rds = form.getElementsByName(name); //select all elements with the radio group name
for(var n=0;n<rds.length;n++){
var rtype = rds[k].getAttribute("radio"); //this is just for security...
if(rtype == "radio" && rds[k].checked){ //if checked...
radios[radios.length] = name; //add the name to radios groups checked
passthru = true; //the group has passed the exam
break; //go away
}
}
}
if(!passthru){ //so.. if the groups doesn't pass the exam
return false;
}
}
}
var ta = form.getElementsByTagName("textarea"); for(var k=0; k<ta.length; k++){ if(ta.value == ""){ return false; } } //for textarea
var selects = form.getElmeentsByTagName("select");
for(var k=0;k<selects.length;k++){ //for select, again quitely complicated
if(selects[k].value == ""){ return false; } //obiusly this first
if(selectDefaultNeeded){ //if default is needed
var opts = selects.getElementsByTagName("option"); //get ops
var defaultValue = ""; //set default value
for(var n=0;n<opts.length;n++){ //getting here the default -if exists- option. attribute (selected)
if(opts[n].hasAttribute("selected")){
defaultValue = opts[k].value;
break;
}
}
if(selectFirstDefault && defaultValue == ""){ defaultValue == opts[0].value; } //this is you use first value as default
if(selects[k].value == defaultValue || defaultValue == ""){ return false; } //if the default is used + empty security value
}
}
return true;
}
Parametros:
id: id del form
selectDefaultNeeded (true/false): Usar el valor por defecto de un combo, como si no estubiera ingresado, (atributo selected)
selectFirstDefault (true/false): Si el anterior es true, usar la primera opcion como defecto
PS: disculpa si me explique mal en todo este post repito vine de pasa
PS2: te todas formas valida en back-end <----------edite esto