I couldn't come up with a logic that, in the case of a successful shipment, would give a message, "Don't go well."



  • There are two fields of entry. Validation came up, all right. But there's a difficulty in creating logic so that if the data from the input's are successfully shipped, it's safe.

    I've tried options that no longer show up to save the place.

    Please give me a clue (maybe another addEventListener in a cycle insert or something)

    'use strict';
    

    let formEl = document.querySelector('form');

    let input_1 = document.querySelector('input#first');
    let input_2 = document.querySelector('input#second');

    let not = document.querySelector('.not')

    formEl.addEventListener('submit', function(e) {
    for (let i = 0; i < 2; i++) {
    if (formEl[i].value === "") {
    formEl[i].style.background = 'red';
    not.style.display = 'block'
    e.preventDefault();
    }
    }
    })

    input {
    border-style: solid;
    margin-bottom: 10px;
    display: flex;
    }
    <form>
    <input id="first" type="text">
    <input id="second" type="text">
    <button>Отправить</button>
    <div class="not" style="display: none;">Поле не заполнено</div><br>

    </form>



  • formEl.addEventListener('submit', function(e) {
      for (let i = 0; i < 2; i++) {
        if (formEl[i].value === "") {
          formEl[i].style.background = 'red';
          not.style.display = 'block';
          e.preventDefault();
          return;
        }
      }
      alert("Success!");
    });
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2