Skip to content
Sign upLog in
← Back to Community

How would I run a function from a js script in html

Profile icon
FriendlyGooseMan

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 [earned 5 cycles]
View Answer
Voters
Profile icon
bajannoir22
Profile icon
FriendlyGooseMan
Comments
hotnewtop
Profile icon
Vandesm14

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

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

script.js

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

Please mark this as answered if I helped your problem 👍

Profile icon
FriendlyGooseMan

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

Profile icon
FriendlyGooseMan

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.

Profile icon
Vandesm14

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

<body onload="cps()">
Profile icon
FriendlyGooseMan

THANK YOU!!!!!

@Vandesm14

Profile icon
FriendlyGooseMan

:D