Home > Net >  Why my secont event listerner won't work after the first one
Why my secont event listerner won't work after the first one

Time:01-27

I have a profile page and there is an edit button. When I click the edit button you can edit the information on the page.

The thing is the second event listener won't work when I click the button done which is appeared after clicking the edit button, nothing changes.

```const editButton = document.querySelector('.edit-btn');
const doneButton = document.querySelector(".done-btn");
const textBox = document.querySelector('.txt-box');
const textArea = document.querySelector('.description');
const pwbox = document.querySelector('.pw-box');
const dateBox = document.querySelector(".date-joined");```
editButton.addEventListener('click', e => {
  textBox.removeAttribute('readonly');
  textArea.removeAttribute('readonly');
  textBox.style.borderBottom = '1px gray solid';
  pwbox.style.display = "flex";
  doneButton.style.display = "block";
  editButton.style.display = 'none';
  dateBox.style.display = "none";
});

doneButton.addEventListener('click', e => {
  textBox.setAttribute("readonly");
  textBox.style.removeProperty('background color');
  textBox.style.removeProperty('border-bottom');
  pwbox.style.display = "none";
  doneButton.style.display = "none";
  editButton.style.display = 'block';
  dateBox.style.display = "flex";
});
<div >
  <input type="text" name="uname"  value="<?php echo $usersName ?>" readonly autocomplete="off">
  <input type="text" name="email" class='email' value="<?php echo $usersEmail ?>" readonly>
  <div >
    <label for="password">Password</label>
    <input type="password" name="password" >
    <label for="confirmPassword">Confirm Password</label>
    <input type="password" name="conf-password" >
  </div>
  <div >
    <small>Date Joined</small>
    <div>01/01/01</div>
  </div>

</div>
<div >

  <textarea name="description"  cols="30" rows="10" placeholder="Let me describe you!" readonly></textarea>
  <button class='edit-btn'>Edit</button>
  <button >Done</button>

</div>

CodePudding user response:

Instead of using an event listener, you could probably use this and call a function when you click the button <input type="button" onclick="editFunction()" value="Edit" />

CodePudding user response:

The problem is the .setAttribute in my js file, it need 2 parameters instead of one. Thanks for helping out.

  •  Tags:  
  • Related