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>
asked Nov 22, 2022 at 22:35
6
  • When do you want the function to work exactly? When clicking the signup button? Commented Nov 22, 2022 at 22:39
  • it should work alongside the check function that is executed by both passwords with onkeyup Commented Nov 22, 2022 at 22:40
  • So you want to remove the p tag by executing the removeRow function? Commented Nov 22, 2022 at 22:45
  • edited the code. i want all elements with the id of message to get removed and added Commented Nov 22, 2022 at 22:51
  • 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. Commented Nov 22, 2022 at 22:57

1 Answer 1

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")

answered Nov 22, 2022 at 23:02
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.