JavaScript Read Only

From All n One's bxp software Wixi

Revision as of 17:25, 11 April 2012 by Philip Lacey (talk | contribs)
Jump to: navigation, search

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.