Answers for "getting empty string in javascript input"

1

how to make input field empty in javascript

Assuming the element you want to change has the id question, so you can do

document.getElementById("question").value = "";
Posted by: Guest on March-18-2021
0

javascript check if input is empty

<!-- check if any input field in "Form" is empty using JS -->

<script type="text/javascript">
  function validateForm() {
    var a = document.forms["Form"]["answer_a"].value;
    var b = document.forms["Form"]["answer_b"].value;
    if (!a || !b) {
      alert("Please Fill All Required Fields");
      return false;
    }
  }
</script>

<form method="post" name="Form" onsubmit="return validateForm()" action="">
  <input type="text" name="answer_a" value="">
  <input type="password" name="answer_b" value="password">
</form>
Posted by: Guest on November-07-2021

Code answers related to "getting empty string in javascript input"

Code answers related to "Javascript"

Browse Popular Code Answers by Language