Button not enable right click and copy paste some text

Viewed 245

I'm added text type and button enable disable function , but when I right click and copy paste button not enable , any solution for this?

Thanks

function manage(txt) {
  var bt = document.getElementById('btSubmit');
  if (txt.value != '') {
    bt.disabled = false;
  } else {
    bt.disabled = true;
  }
}

 
<input type="text" id="txt" onkeyup="manage(this)" />
<input type="submit" id="btSubmit" disabled />

2 Answers

You could do with oninput event.

function manage(txt) {
  var bt = document.getElementById('btSubmit');
  if (txt.value != '') {
    bt.disabled = false;
  } else {
    bt.disabled = true;
  }
}
<input type="text" id="txt" oninput="manage(this)" />
<input type="submit" id="btSubmit" disabled />

In that case you need to use onpaste event.

document.getElementById("txt").onpaste = manage;

function manage(txt) {
        var bt = document.getElementById('btSubmit');
        if (txt.value != '') {
            bt.disabled = false;
        }
        else {
            bt.disabled = true;
        }
    }
<input type="text" id="txt" onkeyup="manage(this)" />
    <input type="submit" id="btSubmit" disabled />
    

More info about that event: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/onpaste

Related