Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
Hello. my problem is i need in some cases make some fields read only and in other the same fields set not readonly. if someone could help me, I would be very grateful, thanks!
Posted

Hi,


You can try with JavaScript.

C#
function toggleEnable(oName){
var txtBox;
txtBox =document.getElementById(oName);
try
 {
   txtBox.readOnly = !txtBox.readOnly;
 }
 catch(e)
 {
    txtBox.readOnly=false;
 }}



Happy Coding
 
Share this answer
 
v2
You could use jQuery[^] to toggle the fields, if you already assigned the textboxs (which require toggling) with a class.

C#
$('.toggle:text').attr('readonly', ( $('.toggle:text').attr('readonly') == 'readonly' ? '' : 'readonly' ) );


So now, every <input type="text" class="toggle" name="example" /> will now toggle between readonly and editable.

Notice that it will only change input fields of type 'text', with a class of 'toggle'.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900