0

so i found this thread, but I can't figure out how to actually call the functions.

i have tried:

removeRow('message')

and

removeRow(document.getElementById('message'))

i am using the accepted answer and my html is

      <form action="http://localhost/signup.php" method="post" style="display:inline-block; margin:0 auto;">
         <label for="username">Username</label>
         <br>
         <input type="text" name="username" id="username" placeholder="Username" required>
         <br>
         <label for="password">Password</label>
         <br>
         <input type="password" name="password" id="password" placeholder="Password" onkeyup='check();' required>
         <br id="message">
         <p id="message"></p>
         <br id="message">
         <label for="confirm_password">Confirm Password</label>
         <br>
         <input type="password" name="confirm_password" id="confirm_password" placeholder="Password" onkeyup='check();' required>
         <br>
         <label for="Email">Email Address</label>
         <br>
         <input type="email" name="email" id="email" placeholder="Email" required>

         <button type="submit" id="signup">
            Sign up
         </button>
      </form>
Cronk
  • 11
  • 2
  • When do you want the function to work exactly? When clicking the signup button? – DreamBold Nov 22 '22 at 22:39
  • it should work alongside the check function that is executed by both passwords with onkeyup – Cronk Nov 22 '22 at 22:40
  • So you want to remove the `p` tag by executing the `removeRow` function? – DreamBold Nov 22 '22 at 22:45
  • edited the code. i want all elements with the id of message to get removed and added – Cronk Nov 22 '22 at 22:51
  • Add the function declaration `function removeRow(elementId){ document.getElementById(elementId) }` and call it with `onkeyup="removeRow('message')" `. Is it what you need? – DreamBold Nov 22 '22 at 22:54
  • 2
    If you copy/pasted from that other post, the removeRow function they defined there is specifically looking for an element that is a child of 'content.' I'm guessing that might be what happened, but you didn't include your function definitions. – William Nov 22 '22 at 22:57

1 Answers1

0

The function in the original answer is :

function removeRow(input) {
    input.parentNode.remove()
}

So the expected parameter of the function is an element and the function removes element's parent. If you want to remove the element with id #message, just change the function to:

function removeRow(element) {
  element.remove()
}

PS: the ids should be unique, if you have multiple element with the same you should use a class and the selector will be document.getElementsByClassName("message")

voidbrain
  • 351
  • 1
  • 3
  • 13