Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
How to set modal on every input value JS

How I can set a modal for each input value? In Vanilla JS, are there any examples?

Here is my full code https://codesandbox.io/s/modal-forked-redh0c

With addTask I create the element

and every element should have modal,

modal should be unique for every single element

How I can do so?

//add new task functional
function addTask() {
    const btn = document.querySelector('.add__btn');
    const addBtn = document.querySelector('.add__item-btn');
    const cancelBtn = document.querySelector('.cancel__item-btn');
    const textarea = document.querySelector('.textarea');
    const form = document.querySelector('.form');

    //get value from textarea and put it val.
    let value;

    btn.addEventListener('click', () => {
        //show and hide form and btn
        form.style.display = 'block';
        btn.style.display = 'none';
        addBtn.style.display = 'none';

        //get value and show/hide btn
        textarea.addEventListener('input', (e) => {
            value = e.target.value;
            if (value) {
                addBtn.style.display = 'block';

            } else {
                addBtn.style.display = 'none';
            }
        });

    });

    //delete  all
    cancelBtn.addEventListener('click', () => {
        textarea.value = '';
        value = '';
        form.style.display = 'none';
        btn.style.display = 'flex';
        dragNdrop();
    });

    //add element in board
    addBtn.addEventListener('click', () => {
        const newItem = document.createElement('div');
        newItem.classList.add('list__item');
        newItem.draggable = true;
        newItem.textContent = value;
        lists[0].append(newItem);
        //clear info from textarea and form
        textarea.value = '';
        value = '';
        form.style.display = 'none';
        btn.style.display = 'flex';
        dragNdrop();
    });

}

addTask();


function openModal() {
    const lists = document.querySelectorAll('.list');

}
openModal()
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!