javascript - jQuery set button element active and disabled dynamically -


i'm working on client side script using jquery.

i achieve set button element disabled or enabled, when enter or delete text in 1 input field.

however, need check if 2 input fields have value, otherwise buttons should disabled. though, buttons enabled if put text in 1 input field...

html

<button type="button" id="btnsave">save</button> <button type="button" id="btnsubmit">save</button>  <input type="text" id="businesslineidlist" /> <input type="text" id="label" /> 

js

$("#businesslineidlist").on("keyup", function () {      checkbusinessline();      checklabel(); });  $("#label").on("keyup", function () {      checklabel();      checkbusinessline(); });  function checklabel() {     if ($("#label").val()) {         setbtnactive();     } else {         setbtndisabled()     }; }  function checkbusinessline() {     if ($("#businesslineid").val()) {         setbtnactive();     }     else {         setbtndisabled();     } }  function setbtnactive() {     $("#btnsave").removeattr("disabled");     $("#btnsubmit").removeattr("disabled"); };  function setbtndisabled() {     $("#btnsave").attr('disabled', true);     $("#btnsubmit").attr('disabled', true); }; 

do have idea how solve issue? thanks

every time 1 has changed, check both of them , act according result of that:

$("#businesslineidlist").on("keyup", callback); $("#label").on("keyup", callback);  function callback() {      if (islabelhasvalue() && isbusinesslinehasvalue()) {         setbtnactive();      } else {         setbtndisabled();      } }  function islabelhasvalue() {     return $("#label").val() && $("#label").val().length > 0; }  function isbusinesslinehasvalue() {     return $("#businesslineid").val() && $("#businesslineid").val().length > 0; }  function setbtnactive() {     $("#btnsave").removeattr("disabled");     $("#btnsubmit").removeattr("disabled"); };  function setbtndisabled() {     $("#btnsave").attr('disabled', true);     $("#btnsubmit").attr('disabled', true); }; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -