+ 2

Button "onlick" affecting "textarea" required?

https://sololearn.com/compiler-playground/W1Dt3ZOXoqDO/?ref=app That's my code. I was trying to apply '.checked' to checkbox input through button that is calling function in the script. So, when the button get clicked, the checkbox is marked. But, the 'textarea' tag also got affected and popping up "fill out...."

12th Dec 2023, 2:53 AM
W-UD
4 ответов
+ 4
Try adding the type="button" attribute to both of your top buttons. This behavior is happening for you because your buttons do not have a "type" specified and are inside a form. Because of this, they are being treated as submit buttons, which isn't what you're wanting here. When inside a <form> element, it's good practice to be clear what inputs/buttons are being used for. Happy coding!
12th Dec 2023, 3:18 AM
Daniel C
Daniel C - avatar
0
if you are not actually doing any post request, you can omit the <form></form> tags.
12th Dec 2023, 12:29 PM
Bob_Li
Bob_Li - avatar
0
Bob_Li no, i was just testing it just in case there is a situation where i want to build form like that later.
12th Dec 2023, 1:42 PM
W-UD
0
Daniel C yeah thanks. That really worked.
12th Dec 2023, 1:43 PM
W-UD