Search code examples
javascriptjqueryyii2fielddisabled-input

Yii2 disable field


In yii2 I have two fields (Text1 and Text2). I want to disable the second field (Text2) if the first field (Text1) is not null. I think this can be done with javascript but I dont't really know. Can anybody help me?


Solution

  • <script>
    
    var textbox1 = document.getElementById("id1");
        textbox1.onkeyup = function(){
        value = document.getElementById("id1").value;
        if(value.length != 0){
         document.getElementById("id2").disabled = true;
        }
        else {
          document.getElementById("id2").disabled = false;
        }
     };
    
    <script>