1
I wanted to make a form but without using <form>
because I intend to send the inputs
for ajax
. The problem is that if you take the form, it will not be required because as you have said in W3schools
The attribute required specifies that a
input
must be filled before to be submitted
So, what can I do to get it? I searched and found this code:
document.getElementById('put_id_here').validity.valid;
But the above code did not work.
This works well https://jsfiddle.net/Sergio_fiddle/97k5n5yj/ what is the problem you are having?
– Sergio
Try adding a button
<button>
. I tried and gave no reply– I_like_trains
I had the ill-defined id on what I tried but I wanted him to give Trigger to the required, and not say whether it is empty or not
– I_like_trains
@I_like_trains ok, if you want to use the native UI this doesn’t work without
form.submit
. You can make your own, using the.validity.valid
. But if you want it to be automatic via browser use<form>
and then prevents it from being submitted withe.preventDefault();
– Sergio
@Sergio On second thought, I think I’ll just change the color of the border to red with a more simple and pleasant side warning. Post your answer and I’ll accept it.
– I_like_trains
@I_like_trains done. I’ve put together one more idea that might be useful:
:empty
of the CSS– Sergio