Here's an option for you to use.
Put the below code into your page. Then called the javascript function
enableFormEleme nt on page load. Use the below function call:
enableFormEleme nt( <form element>, <Is the element editable (true/false)> )
That will allow you to make checkbox's, radio button, textboxs, textareas,
etc, ALL either editable or not.
Now don't say I never gave you anything!
Enjoy
Chaitanya Marvici
Code below:
----------------------------------------------------------------------------
------------------------------------------------------------------
function enableFormEleme nt( element, editable ) {
if( element.length && ( ( element.name + "" ) == "undefined" ) ) { //This is
used if a group of elements, all with the same name
for( var x = 0; x < element.length; x++ ) { //is sent to the function. It
will loop through and recursively
enableFormEleme nt( element[x], editable ); //call this function to correctly
turn the readonly stuff off/on.
}
} else {
if( ( element.type != "hidden" ) && ( element.type != "button" ) && (
element.type != "image") ) {
var focusStr = element.onfocus + "";
var clickStr = element.onclick + "";
var changeStr = element.onchang e + "";
var focusFunction, clickFunction, changeFunction;
focusStr = trim( focusStr.substr ing( focusStr.indexO f("{") + 1,
focusStr.lastIn dexOf("}") ) );
clickStr = trim( clickStr.substr ing( clickStr.indexO f("{") + 1,
clickStr.lastIn dexOf("}") ) );
if( element.type.in dexOf( "select" ) >= 0 ) {
changeStr = trim( changeStr.subst ring( changeStr.index Of("{") + 1,
changeStr.lastI ndexOf("}") ) );
}
if( ! editable ) {
if( ( browserType == IE ) || ( browserType == Nav6 ) ) { element.readonl y =
true; }
focusFunction = new Function( "e", "blurElemen t( this );\n" + focusStr )
clickFunction = new Function( "e", "blurElemen t( this );\n" + clickStr )
if( element.type == "radio" || element.type == "checkbox" ) {
element.checked Temp = element.checked ;
}
if( element.type.in dexOf( "select" ) >= 0 ) {
changeFunction = new Function( "e", "resetEleme nt( this );\n" + changeStr )
}
} else {
var strStart;
if( ( browserType == IE ) || ( browserType == Nav6 ) ) { element.readonl y =
false; }
strStart = focusStr.lastIn dexOf( "blurElemen t( this );" );
if( strStart != -1 ) { focusFunction = new Function( "e", focusStr.substr (
strStart + "blurElemen t( this );".length, focusStr.length ) ) }
strStart = clickStr.lastIn dexOf( "blurElemen t( this );" );
if( strStart != -1 ) { clickFunction = new Function( "e", clickStr.substr (
strStart + "blurElemen t( this );".length, clickStr.length ) ) }
if( element.type.in dexOf( "select" ) >= 0 ) {
strStart = changeStr.lastI ndexOf( "resetEleme nt( this );" );
if( strStart != -1 ) { changeFunction = new Function( "e",
changeStr.subst r( strStart + "resetEleme nt( this );".length,
changeStr.lengt h ) ) }
}
}
if( typeof( focusFunction ) != "undefined" ) { element.onfocus =
focusFunction; }
if( typeof( clickFunction ) != "undefined" ) { element.onclick =
clickFunction; }
if( element.type.in dexOf( "select" ) >= 0 ) {
if( typeof( changeFunction ) != "undefined" ) { element.onchang e =
changeFunction; }
}
} // End check for form element type
}
}
function enableElements( f ) {
var numOfElements = f.length
var setFocus = false;
var proxyMarker = "Proxy";
for ( e = 0; e < numOfElements; e++ ) {
var visibleElement = f.elements[e];
var valueElement = f.elements[e];
if ( visibleElement. type=="checkbox ") {
var visibleElementN ame = visibleElement. name;
if ( visibleElementN ame.indexOf(pro xyMarker) >= 0 ) { // if proxy checkbox
var valueElementNam e = visibleElementN ame.substring( 0,
visibleElementN ame.indexOf(pro xyMarker) );
valueElement = f.elements[ valueElementNam e ];
}
}
enableFormEleme nt( visibleElement, isElementEditab le( valueElement ) );
}
}
function blurElement( element ) {
if( element.type == "radio" || element.type == "checkbox" ) {
if( eval( "document." + element.form.na me + "." + element.name +
".length" ) ) {
for( var x = 0; x < eval( "document." + element.form.na me + "." +
element.name + ".length" ); x++ ) {
eval( "document." + element.form.na me + "." + element.name + "[" + x +
"].checked = " + "document." + element.form.na me + "." + element.name + "["
+ x + "].checkedTemp ? true : false;" );
}
} else {
element.checked = element.checked Temp ? true : false;
}
}
if( element.type.in dexOf( "select" ) >= -1 ) {
element.selectI ndexTemp = element.selecte dIndex;
}
element.blur();
}
function resetElement( element ) {
if( element.type.in dexOf( "select" ) >= -1 ) {
element.selecte dIndex = element.selectI ndexTemp;
}
}
"/.." <no*******@ix.n etcom.com> wrote in message
news:v0******** *************** *********@4ax.c om...
By Mon, 21 Jul 2003 18:06:43 -0700, "Steve C. Orr, MCSD"
<St***@Orr.ne t> decided to post
"Re: Read Only Checkbox(list) ?" to
microsoft.publi c.dotnet.framew ork.aspnet:
You might consider this is a bit of a hack, but how about changing the
background color of the page or panel so there is greater contrast with
thegrayed out checkboxes? Simplicity sells.
Thanks for the suggestion,
but since it goes out to serious clients, I think that I'm looking
for a bit more serious of a solution. I had a thought that I should
look into making a custom control. Don't know anything about it, but
it's probably a reasonable way to go.
My other thought is to take screenshots of a checked and unchecked
checkbox, they wind up less than 1KB (16px X 16px: bmp) in size,
and arrange like 85 pairs of them, then programmaticall y set the
appropriate one visible based on the boolean value from the database.
But that seems extreme. It's probably close to what a custom control
would actually do.
There has to be a frequent solution to this!!!
(Displaying a boolean value in a 'read-only' checkboxlist -- I need
to do 85 or so of the items on a report page.)
Ciao,
/ts