+ 1

How to fix function is not defined error in Javascript?

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <input type="text" id="text"> <button type="button" onclick="myfunction()">reset</button> </body> </html> /*js*/ function myfunction() { document .getElementById("text").innerHTML=""; } myfunction();

11th Jan 2022, 3:00 AM
MANIKANDAN S
MANIKANDAN S - avatar
3 Answers
+ 6
To clear a text input, assign blank string to 'value' attribute (not innerHTML attribute) document .getElementById("text").value = ""; And don't call myfunction in JS tab If you use a <form> then an input with 'type' attribute "reset" will do the same thing.
11th Jan 2022, 4:22 AM
Ipang
+ 2
Ipang Thanks, I did not remember that, this looks a lot better than having to use functions jaja <form> <input> <input type=reset> </form>
11th Jan 2022, 4:31 AM
CGM
CGM - avatar
+ 1
Defining the function haha ​​.. attach your code so we can help you!
11th Jan 2022, 3:02 AM
CGM
CGM - avatar