Geting field values (Radio buttons/Checkboxes/Comboboxes)

There are different ways to retrieve values from each of these field types.
JavaScript

RADIO BUTTONS

for (var i=0;i<document.forms[0].FIELDNAME.length;i++) {
	if (document.forms[0].FIELDNAME[i].checked) {
    		alert(document.forms[0].FIELDNAME[i].value) ;
    	}
}






CHECKBOXES - (single and double) Single is not an array

var cb = document.forms[0].FIELDNAME; 
var selectcount = 0; 
var docUNID = new Array();
if (cb.length) {
	//has more than one value
	for(i = 0; i < cb.length; i ++){
		if (cb[i].checked){
			docUNID[selectcount] = cb[i].value; 
			selectcount++;
		}
	} 
} else {
	//has only one value
	if (cb.checked){
		docUNID[selectcount] = cb.value; 
		selectcount++;
	}
}

COMBOBOXES (selectedIndex method - by ID) BEST!

var fld = document.getElementById('FIELDIDVALUE');

tmp = fld.options[fld.options.selectedIndex].text ;

alert(tmp)

COMBOBOXES (selectedIndex method - by form)

var fld = document.forms[0].sType;

tmp = fld.options[fld.options.selectedIndex].text ;

alert(tmp)

COMBOBOXES (loop method)

for ( i=0 ; i<document.forms[0].FIELDNAME.length ; i++ ){
	if (document.forms[0].FIELDNAME.options[i].selected == true) {
		sourcetypevar = document.forms[0].FIELDNAME.options[i].text
	}
}

Posted by fbrefere001 on Wednesday February 11, 2004