JavaScript Read Only
From All n One's bxp software Wixi
readOnly is a lovely way of protecting your customer data in a database where some data is preloaded.
The fastest way of implementing this is to use BEs onFocus box when editing a question and add in
this.blur();
That will stop any editing of the box but can break up the flow of tabbing through the document.
Another alternative and the one we recommend is to put in the onFocus box
this.defaultIndex=this.selectedIndex;
and in the onChange to put
this.selectedIndex=this.defaultIndex;
An alternate, but which doesn't work on drop down lists is
document.getElementById("fieldnameHere").readOnly=true;
When you have data loaded into a database, the customers data will generally be presented to an agent / user. You may not want them editing particular details like a customer Id or reference details.
Simple put a readOnly statement into the onLoad event of the database and those fields will not be editable by the user.
Do NOT use the disabled command as this will cause those fields to be wiped. This is a common mistake in JavaScript coding, where
database updates are involved.
Unfortunately Dropdown list do not allow the attribute read-only, and if we user disable no data will be saved. To get around this user the below JavaScript function, this function can work on ant dropdown list in bxp
function fn_DropdownList_ReadOnly( strObjectIdDDL ){
var objDropDownListToLock = document.getElementById(strObjectIdDDL);
if (objDropDownListToLock.value != ''){
var strText = objDropDownListToLock.options[objDropDownListToLock.selectedIndex].text;
var strValue = objDropDownListToLock.value;
objDropDownListToLock.length = 0;
objDropDownListToLock.options[objDropDownListToLock.length] = new Option(strText, strValue);
}
}