\n\n\n","upvoteCount":7},{"@type":"Answer","text":"You need the script tag.","upvoteCount":6},{"@type":"Answer","text":"♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦ check the JS tutorial. As already mentioned, the way you do it on code playground is different from when you write code outside SL.","upvoteCount":5},{"@type":"Answer","text":"Check out this link:\nhttp://www.simplehtmlguide.com/javascript.php","upvoteCount":5},{"@type":"Answer","text":"♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦ \nUse event attributes to call them in html (search about it on google)\n\nBut I personally don't prefer to call functions in html! I prefer to use event listeners!","upvoteCount":5},{"@type":"Answer","text":"Galaxy-Coding (CodeWarrior) \nnow think on when calling from diff file. you make much sense.thanks bro","upvoteCount":5},{"@type":"Answer","text":"Include Js file in HTML then call the function by inline or event call.","upvoteCount":5},{"@type":"Answer","text":"You can use a button to call your JS function\n\n","upvoteCount":4},{"@type":"Answer","text":"♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦ \nIn SoloLearn HTML, CSS and Javascript are written into sections in Code Playground editor. But if we work outside SoloLearn, HTML, CSS and Javascript codes can be written into separate files. Importing CSS or Javascript makes sense only when we work outside SoloLearn.","upvoteCount":4},{"@type":"Answer","text":"Ipang explain in detail pls","upvoteCount":3},{"@type":"Answer","text":"if that above code is correct.\nIpang two question arise there\n(1) how can i import and execute js there.\n(2)how can that be automatic.\nif not explain deeper","upvoteCount":3},{"@type":"Answer","text":"♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦ \nThere are detailed answers to your question already as far as I understand your question.\n\nIf you need more help or want something explained in more detail, please also give more details on what we can help you with and where exactly you're stuck and what you have tried.\n\nThe script you sent for [user id=\"5117788\"]Ipang[/user] works as intended I guess. What was your question there?\nWhat do you mean by import and execute?\nAnd what do you want to be automatic?","upvoteCount":3},{"@type":"Answer","text":"Sonic show an example pls,go to previous comment and see the code i made and then import js function for me","upvoteCount":3},{"@type":"Answer","text":"Sonic how sir","upvoteCount":3},{"@type":"Answer","text":"You can use script tag to load js code in html file\n\nand you can use event attributes like on click , on drag","upvoteCount":3},{"@type":"Answer","text":"\n
\n \nlike this then how do we connect the script with the js code","upvoteCount":3},{"@type":"Answer","text":"\n
+ 7

how to call various javascript function into html

i have create a various js code with function. i want to call those function into html. how can i do that

21st Sep 2020, 3:14 PM
Dove
Dove - avatar
46 Answers
+ 10
Look. Here’s the answer You make a button. That button looks like this: <button onPress=“dostuff()”>CLICK HERE></button> That means that on button press, whatever is in the quotes is Js and is runned. Now, in the JS code write: function dostuff() { //PUT ANY JS CODE YOU WANT HERE } the function do stuff is just a short way of saying everything that’s where ”//PUT ANY JS CODE YOU WANT HERE” is printed understand?
22nd Sep 2020, 12:56 PM
Galaxy-Coding (inactive)
Galaxy-Coding (inactive) - avatar
+ 7
You can use HTML element attributes, for example: <button onclick=handleClick()>Click me</button>
21st Sep 2020, 3:22 PM
Bagon
Bagon - avatar
+ 7
Ipang what of something like this <!DOCTYPE html> <html> <body> <h1>The onclick Event</h1> <p>The onclick event is used to trigger a function when an element is clicked on.</p> <p>Click the button to trigger a function that will output "Hello World" in a p element with id="demo".</p> <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "Hello World"; } </script> </body> </html>
21st Sep 2020, 3:42 PM
Dove
Dove - avatar
+ 6
You need the script tag.
21st Sep 2020, 10:20 PM
Sonic
Sonic - avatar
+ 5
♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦ check the JS tutorial. As already mentioned, the way you do it on code playground is different from when you write code outside SL.
21st Sep 2020, 10:38 PM
Sonic
Sonic - avatar
21st Sep 2020, 10:49 PM
Sonic
Sonic - avatar
+ 5
♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦ Use event attributes to call them in html (search about it on google) But I personally don't prefer to call functions in html! I prefer to use event listeners!
21st Sep 2020, 10:53 PM
Namit Jain
Namit Jain - avatar
+ 5
Galaxy-Coding (CodeWarrior) now think on when calling from diff file. you make much sense.thanks bro
22nd Sep 2020, 1:00 PM
Dove
Dove - avatar
+ 5
Include Js file in HTML then call the function by inline or event call.
22nd Sep 2020, 3:16 PM
Programmer Rushikesh
Programmer Rushikesh - avatar
+ 4
You can use a button to call your JS function <button type="button" onclick="fun()">call function fun</button>
21st Sep 2020, 3:21 PM
Ipang
+ 4
♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦ In SoloLearn HTML, CSS and Javascript are written into sections in Code Playground editor. But if we work outside SoloLearn, HTML, CSS and Javascript codes can be written into separate files. Importing CSS or Javascript makes sense only when we work outside SoloLearn.
21st Sep 2020, 4:07 PM
Ipang
+ 3
Ipang explain in detail pls
21st Sep 2020, 3:24 PM
Dove
Dove - avatar
+ 3
if that above code is correct. Ipang two question arise there (1) how can i import and execute js there. (2)how can that be automatic. if not explain deeper
21st Sep 2020, 3:45 PM
Dove
Dove - avatar
+ 3
♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦ There are detailed answers to your question already as far as I understand your question. If you need more help or want something explained in more detail, please also give more details on what we can help you with and where exactly you're stuck and what you have tried. The script you sent for Ipang works as intended I guess. What was your question there? What do you mean by import and execute? And what do you want to be automatic?
21st Sep 2020, 9:41 PM
Martin Möhle
Martin Möhle - avatar
+ 3
Sonic show an example pls,go to previous comment and see the code i made and then import js function for me
21st Sep 2020, 10:32 PM
Dove
Dove - avatar
+ 3
Sonic how sir
21st Sep 2020, 10:39 PM
Dove
Dove - avatar
+ 3
You can use script tag to load js code in html file and you can use event attributes like on click , on drag
22nd Sep 2020, 10:03 AM
Master Genius [ INACTIVE ]
Master Genius [ INACTIVE ] - avatar
+ 3
<body onload="brython()"> <div id="board"></div> </body> like this then how do we connect the script with the js code
22nd Sep 2020, 11:19 AM
Dove
Dove - avatar
+ 3
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.7.1/brython.min.js"> </script> <script> this is the script
22nd Sep 2020, 11:23 AM
Dove
Dove - avatar
+ 3
Your script tag should be in head otherwise it will give error because, js must load before it is used
22nd Sep 2020, 11:42 AM
Master Genius [ INACTIVE ]
Master Genius [ INACTIVE ] - avatar