Javascript disabled change form field or button properties

 HTML button has a disabled attribute, which is used to disable the function of the button. In addition to controlling the button button, the disabled attribute can also control the use of other block functions, such as text input boxes, option buttons, or drop-down menus. For items, generally speaking, you can preset the field status when the webpage is opened, for example, it is disabled at the beginning, only the form fields are displayed, or the default is to fill in data, but when the webpage is opened, how to change the disabled attribute What? Through JavaScript can do.


Javascript disabled change form field example
<script language="javascript">
function ChangeDisabled(value){
 if(value=='1'){
 document.getElementById('TetstText').disabled=false; // Change the field to be available
 }else{
 document.getElementById ('TetstText').disabled=true; // Change the field to be disabled
 }
}
</script>
<input type="text" id="TetstText">
<input type="button" value='Change the field to Available' onclick="ChangeDisabled(1)">
<input type="button" value='Change the field to disabled' onclick="ChangeDisabled(2)">
The results are presented as

default, the text field in this example can be filled with data, but we have added two buttons to control the disabled value of the field. When the web page is just opened, the first A button that changes the field to be available will not respond, and the button that changes the field to be disabled will immediately use up the text field and cannot enter text. The document.getElementById('TetstText').disabled in the JavaScript function is used to change the syntax of the disabled attribute, false means disabled is invalid, that is, the field is available, on the contrary, true is to make the disabled of the field effective to achieve full use effect. 

Post a Comment

0 Comments