Javascript DOM HTML Input Search required Property set

Introduction

Set a search field to be a required part of form submission:

document.getElementById("mySearch").required = true;

Click the button to set the required property for the search field.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Search: <input type="search" id="mySearch" name="filter">
  <input type="submit">
</form>/* w ww.  j  av  a 2  s  .  c  om*/
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("mySearch").required = true;
  document.getElementById("demo").innerHTML = "The required property was set.";
}
</script>

</body>
</html>



PreviousNext

Related