Men-Disable semua input type dalam Div Element dengan jQuery

#field1 -> berisi input form
#field1 -> berisi input form

Pilih salah satu yang mau diinput pake dropdown.

javascript :

<script type="text/javascript">
$(document).ready(function(){
    dis(document.getElementById("field2"));
});

/// hide / show elements using dropdown
$('#dropdown_id').on('change', function(e){
var val = $(this).attr('value');
if(val == '1'){
     $('#field1').show();
     $('#field2').hide();
     dis(document.getElementById("field2"));
     if(document.getElementById("field1").disabled == true){ dis(document.getElementById("field1")); }
}else{
     $('#field2').show();
     $('#field1').hide();
     dis(document.getElementById("field1"));
     if(document.getElementById("field2").disabled == true){ dis(document.getElementById("field2")); }
     
}
});

/// disabled input element inside div id
function dis(el){
    try {
	el.disabled = el.disabled ? false : true;
    }catch(E){
    
    }
    if (el.childNodes && el.childNodes.length > 0){
	for (var x = 0; x < el.childNodes.length; x++) 
	{
	    dis(el.childNodes[x]);
	}
    }
}

</script>
Advertisements
This entry was posted in php. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s