Software Technology Tips

By using the following  javascript function you can dynamically set the status of all controls of a form to readonly or disable depending upon which attribute (readonly or disable) the particular control supports. Further, you can also enable/disable controls according to their type by slightly modifying the code. ( toggle boolean property of the control )

 

Call the  function below in body onload event  to disable all controls of the page during loading.

function disablePage()
{
 
   var controlType;
 
   for (var i = 0; i < document.forms[0].elements.length; i++)
 
  { 
       controlType = document.forms[0].elements[i].type;
        if (controlType == 'select-one' )
 
            {
 document.forms[0].elements[i].readOnly = true;
 document.forms[0].elements[i].disabled = true;
             }
 
                if (controlType == 'text' || controlType=='hidden')
            {
                document.forms[0].elements[i].readOnly = true;
             }
 
   if (controlType == 'checkbox')
             {
   document.forms[0].elements[i].disabled = true;
              }
                 if (controlType == 'textarea')
            {
document.forms[0].elements[i].readOnly = true;
            }
    }
 
 


Related Tags:

JavaScript

Author: Santono Patra

JavaScript

Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

copyright (c) Mindfire Solutions 2007-2014. Login