Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mayeenulislam/8ce49df0b053698b6947da24ec56de9a to your computer and use it in GitHub Desktop.
Save mayeenulislam/8ce49df0b053698b6947da24ec56de9a to your computer and use it in GitHub Desktop.
Find the hidden fields hidden, and are blocking the form submission. Source: cannot remember
<html>
<body>
<form id="my-form-id-here">
<input type="text" style="display: none"><br/>
<input type="text">
<button type="submit">Submit</button>
</form>
<script>
var targetForm = document.getElementById('my-form-id-here');
if (targetForm.checkValidity() == false) {
var list = targetForm.querySelectorAll(':invalid');
for (var item of list) {
console.log(item); // Show the fields in console (good for invisible fields)
item.setAttribute("style", "background-color: red;"); // Highlight them in red if visible.
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment