Warning if required inputs are not selected

前端 未结 1 1424
慢半拍i
慢半拍i 2021-01-27 03:20

How can I add a warning to #printpage when its disabled if its chosen saying please check required fields?

相关标签:
1条回答
  • 2021-01-27 03:49

    You can use JS function checkValidity(), this will return false if the form is not valid.

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/checkValidity

    isValid = $('.form').checkValidity()
    
    if (!isValid) {
      $('#printpage').innerText = "Please fill in required fields";
      } else {
      $('#printpage').innerText = "";
    }
    

    Your html should contain HTML validity checkers, such as required.

    <input required type="text" class="thisIsAClass" />
    
    0 讨论(0)
提交回复
热议问题