+ 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();
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.
+ 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>
+ 1
Defining the function haha ââ.. attach your code so we can help you!