DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Disable Your Form

11.25.2010
| 2749 views |
  • submit to reddit
        // This function disable your entire form. Its purpose is to disable a form field, in order for your ajax request to do its job without being disturbed.

"cond" is the condition. True will disable all your form, False will unlock it.
"myForm" is the ID of your <form></form>

function DisableForm(myForm,cond){
var node_list = getElementById(myForm).getElementsByTagName('input');
	for (var i = 0; i < node_list.length; i++) {
		var node = node_list[i];
		if (node.getAttribute('type') == 'checkbox' || node.getAttribute('type') == 'submit')
		node.disabled = cond; else node.readOnly = cond;
	}
};