Tuesday, January 25, 2011

javascript: how to make Input non editable

Do you want dynamically set the input non-editable?
Here we go:

var setNonEditable=true;
var input =document.getElementById("InputId");
//#1 In this case - the value won't be save in the input field event it presents there
if(setNonEditable)
 {
    input .style.visibility = 'hidden';
 }
else
 {
   input .style.visibility = 'visible';
  }
//#2 The value will be saved even the input is not editable but value is in there
if(setNonEditable)
 {
   input .disabled = true;
 }
else
 {
     input .disabled = false;
  }

Happy easy coding!