Domino Code Fragment

Code Name*
JavaScript function getFieldValue
Date*
04/19/2000
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.
Description*
This function will return the field value (or value list) based on the element type
Type*
JavaScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
function getFieldValue ( theField, vType ) {

//this function will return the field value (or value list) based on the element type

theValue = "";
sep = "";
hits = 0;


//text is the user-entered value as a string
if ( vType == "text" ) return ( theField.value );


//textarea is the user-entered value as a string array of one element
if ( vType == "textarea" ) return ( theField[0].value );


//checkboxes & radio buttons are not so simple
if ( vType == "checkbox" || vType == "radio" ) {


if ( theField.value == null ) {

//if we're here, we are validating a radio button or a nn multi-element checkbox

for ( i = 0; i < theField.length; i++ ) {
if ( theField[i].checked ) {
hits++;
if ( hits > 1 ) {
sep = "; ";
}
theValue += sep + theField[i].value;
}
}
}
return ( theValue );


} else {

//if we are here, must be an ie checkbox, or nn with a one-element checkbox")

if ( navigator.appName == "Microsoft Internet Explorer" ) {

//ie. return some data so we can validate on the server;
return ("can't validate on client")
}


//nn one-element checkbox, see if its checked ...
if (theField.checked ) {
return ( theField.value );


} else {
return ( "" );
}
}


//select is an array of selection pointers to an array of strings representing the choices
if ( vType == "select" ) {


for ( i = 0; i < theField.options.length; i++ ) {
if ( theField.options[i].selected ) theValue += theField.options[i].text
}
return ( theValue );
}
}