Difference between revisions of "JavaScript Read Only"

From All n One's bxp software Wixi

Jump to: navigation, search
Line 37: Line 37:
  
 
[[Category:Topic:JavaScript]]
 
[[Category:Topic:JavaScript]]
 +
[[Category:Topic:Key Concept]]

Revision as of 14:56, 28 November 2014

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.