yii2__
yii2__

Reputation: 177

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?

Upvotes: 0

Views: 448

Answers (1)

Sindhoor
Sindhoor

Reputation: 548

<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>    

Upvotes: 1

Related Questions