The main thing is where I stole it - it works and I don’t = (I can't do it. Tell me how to make it work.
$(document).ready(function() { function valid(form){ var error = false; var name = form.email.value; var name = form.phone.value; if(email == "" || email == " "){ error = "Вы не ввели email"; } else if (phone == ""){ error = "Вы не ввели телефон"; } if(error){ alert(error); } } });
form{ padding: 20px; background-color: #fff; max-width: 320px; margin: auto; position: relative; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form" method="post" name=""> <input type="text" name="email" placeholder="Введите email" i /> <input type="text" name="phone" placeholder="Введите телефон" /> <br /> <input type="button" onclick="valid(document.getElementById('form'))" name="submit" value="Готово" /> </form>
required
attribute in the input. - Visman