T
T
timtimIT2015-09-23 23:19:39
JavaScript
timtimIT, 2015-09-23 23:19:39

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>

Where is it correct to specify return so that the page does not reload (so that you do not have to re-enter the fields that already exist). Tried after alerts - didn't work, after if{} too.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2015-09-24
@timtimIT

in its most primitive form jsfiddle.net/o32a8w7L

I
Ivan Tokar, 2015-09-24
@Jonathan

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 question

Ask a Question

731 491 924 answers to any question