Ask coding questions

← Back to all posts
How would I run a function from a js script in html
LukeShomper (26)

I think the title says it all but is there a way to run a function from a js script in Html.

Answered by Vandesm14 (2010) [earned 5 cycles]
View Answer
Vandesm14 (2010)

It seems that your code is already doing what you want
But just for reference:

<input type="button" onclick="test()">


function test() {
	alert("Hello World!");

Please mark this as answered if I helped your problem 👍

LukeShomper (26)

@Vandesm14 that's on click ;-; I need it on run

LukeShomper (26)

Because in the files there is a script that has a function cps() which enables the +1 Per second to work and when you spam it you get a like 1 every millisecond and so I need a way to run a function 1 time only.

Vandesm14 (2010)

@LukeShomper That's easy too!
just change your body starting tag to this:

<body onload="cps()">