Click here to Skip to main content
14,638,900 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,


You can try with JavaScript.

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



Happy Coding
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

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

$('.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'.
   
v4

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100