Answer the question
In order to leave comments, you need to log in
Where is it correct to specify return false?
Hello.
I am learning js.
There is a code:
<form action="" onsubmit="FormValidate()">
<ul>
<li><label for="name" id="name1">name:</label><input type="text" id="name"></li>
<li><label for="surname">Фамилия:</label><input type="text" id="surname"></li>
<li><label for="phone">Телефон:</label><input type="text" id="phone"></li>
<li><label for="email">Электронная почта:</label><input type="text" id="email"></li>
<li><label for="info">Дополнительная информация:</label><textarea name="" id="info" cols="30" rows="10"></textarea></li>
<li><button type="submit" onclick="">Отправить</button></li>
<li><button >Отправить2</button></li>
</ul>
<p id="par"></p>
</form>
<script>
var str = document.getElementById("name"),
str1 = document.getElementById("surname"),
str2 = document.getElementById("phone"),
str3 = document.getElementById("email"),
str4 = document.getElementById("info");
function FormValidate(){
var string = str.value,
string1 = str1.value,
string2 = str2.value,
string3 = str3.value,
string4 = str4.value;
if (string.search(/[a-z]/) == -1){
alert("Введите имя!");
}
return false;
else if (string1.search(/[a-z]/) == -1){
alert("Введите Фамилию!");
}
return false;
else if (string2.search(/[0-9]/) == -1){
alert("Введите телефон!");
}
else if (string3.search(/@/) == -1){
alert("Введите электронную почту!");
}
else if (str4.value == ''){
alert("Введите информацию!");
}
}
</script>
Answer the question
In order to leave comments, you need to log in
This will not work with the form, you must use the cancellation of the standard behavior of the form
event specify as a parameter of the function you call
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question