I want to return ‘Alert’ box if someone submits empty form

<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, 
    <h1>To Do List</h1>
        <input autocomplete="off" autofocus id="todotext" 
        <input onclick="serve(); return false" type="submit">
    <ol id="add"></ol>


    function serve(){
        const neww = document.getElementById('add')
        let text = document.getElementById('todotext').value
        const a = document.createElement('li')
        a.innerText = text
        document.getElementById('todotext').value = ""

Here is my code and I want to return an 'Alert' if someone submit empty form. How should I do it ?

Here's an image:

This is the Image, Click here

Read more here: https://stackoverflow.com/questions/65840049/i-want-to-return-alert-box-if-someone-submits-empty-form

Content Attribution

This content was originally published by Rakshit Joshi at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: