Javascript DOM HTML Input URL required Property set

Introduction

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

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

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

elements with type="url" are not supported in Safari.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Homepage: <input type="url" id="myURL" name="website">
  <input type="submit">
</form>/*from   w w w.  j a  v  a 2  s .  c o m*/
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

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

</body>
</html>



PreviousNext

Related