WEBDEVLAIR Telegram 3866
👩‍💻 Валидация формы с обратной связью

Создайте форму с одним полем ввода для имени и кнопкой "Отправить". При отправке формы выполните следующие условия:

1. Если поле пустое, отобразите сообщение об ошибке под полем.
2. Если поле заполнено, отобразите сообщение "Форма успешно отправлена!".
3. Сообщение об ошибке исчезает при вводе текста.

Решение задачи🔽

<form id="myForm">
<input type="text" id="nameInput" placeholder="Введите имя" />
<button type="submit">Отправить</button>
<p id="error" style="color: red; display: none;">Поле не должно быть пустым</p>
</form>
<p id="success" style="color: green; display: none;">Форма успешно отправлена!</p>

const form = document.getElementById('myForm');
const nameInput = document.getElementById('nameInput');
const error = document.getElementById('error');
const success = document.getElementById('success');

form.addEventListener('submit', (e) => {
e.preventDefault();
if (nameInput.value.trim() === '') {
error.style.display = 'block';
success.style.display = 'none';
} else {
error.style.display = 'none';
success.style.display = 'block';
nameInput.value = '';
}
});

nameInput.addEventListener('input', () => {
if (nameInput.value.trim() !== '') {
error.style.display = 'none';
}
});
Please open Telegram to view this post
VIEW IN TELEGRAM
2👍21



tgoop.com/webdevlair/3866
Create:
Last Update:

👩‍💻 Валидация формы с обратной связью

Создайте форму с одним полем ввода для имени и кнопкой "Отправить". При отправке формы выполните следующие условия:

1. Если поле пустое, отобразите сообщение об ошибке под полем.
2. Если поле заполнено, отобразите сообщение "Форма успешно отправлена!".
3. Сообщение об ошибке исчезает при вводе текста.

Решение задачи🔽

<form id="myForm">
<input type="text" id="nameInput" placeholder="Введите имя" />
<button type="submit">Отправить</button>
<p id="error" style="color: red; display: none;">Поле не должно быть пустым</p>
</form>
<p id="success" style="color: green; display: none;">Форма успешно отправлена!</p>

const form = document.getElementById('myForm');
const nameInput = document.getElementById('nameInput');
const error = document.getElementById('error');
const success = document.getElementById('success');

form.addEventListener('submit', (e) => {
e.preventDefault();
if (nameInput.value.trim() === '') {
error.style.display = 'block';
success.style.display = 'none';
} else {
error.style.display = 'none';
success.style.display = 'block';
nameInput.value = '';
}
});

nameInput.addEventListener('input', () => {
if (nameInput.value.trim() !== '') {
error.style.display = 'none';
}
});

BY Логово верстальщика


Share with your friend now:
tgoop.com/webdevlair/3866

View MORE
Open in Telegram


Telegram News

Date: |

The group also hosted discussions on committing arson, Judge Hui said, including setting roadblocks on fire, hurling petrol bombs at police stations and teaching people to make such weapons. The conversation linked to arson went on for two to three months, Hui said. Invite up to 200 users from your contacts to join your channel Telegram desktop app: In the upper left corner, click the Menu icon (the one with three lines). Select “New Channel” from the drop-down menu. The initiatives announced by Perekopsky include monitoring the content in groups. According to the executive, posts identified as lacking context or as containing false information will be flagged as a potential source of disinformation. The content is then forwarded to Telegram's fact-checking channels for analysis and subsequent publication of verified information. It’s easy to create a Telegram channel via desktop app or mobile app (for Android and iOS):
from us


Telegram Логово верстальщика
FROM American