마니의 공부방/개발 꼼수

jquery 폼 전체요소 활성화 컨트롤

type1. jquery

Disable All Form Elements 
Another question I have seen a lot lately is how can I disable all of the form elements on the page with JavaScript? Well it is rather simple and only takes a few lines of code. All you need to do is loop through the Form elemnt array and set the disabled property to true to disable the elements and false to enable the elements.

 function DisableEnableForm(xForm,xHow){
   objElems = xForm.elements;
   for(i=0;i<objElems.length;i++){
     objElems[i].disabled = xHow;
   }
 }
To execute the function, you just need to send the form object reference and a boolean value to the function. The following code is an example how to call the function disable the elements as the page is loading.
 window.onload= function(){
   DisableEnableForm(document.Form1,true); 
} 
---------------------------------------------------------------------------------------------------
type2. script

  1. <script>  
  2.         function go(){  
  3.                 if(document.getElementById("chk").checked){  
  4.                         document.getElementById("but").disabled = false;  
  5.                         document.getElementById("tex").disabled = false;  
  6.                 }else{  
  7.                         document.getElementById("but").disabled = true;  
  8.                         document.getElementById("tex").disabled = true;  
  9.                         document.getElementById("tex").value="";  
  10.                 }  
  11.   
  12.         }  
  13. </script>  
---------------------------------------------------------------------------------------------------
type3. jquery

02.<script type="text/javascript">
03.$(document).ready(function () {
04.$('#sameAsShipping').change(function () {
05.if (this.checked) {
06.$('#billingInfo input:text').attr('disabled', 'disabled')
07..each(function (i) {
08.var valueFromShippingInput = $('#shippingInfo input:text:eq(' + i + ')').val();
09.$(this).val(valueFromShippingInput);
10.});
11. 
12.} else {
13.$('#billingInfo input:text').removeAttr('disabled');
14.}
15.}).trigger('change');
16.});
17.</script>