0
how may i use function in external java script file in html pages
9 Respostas
0
Lowercase c in onclick, not capital C. I know, it doesn't follow the camelCase convention. Also, include the brackets when you call a function.
onclick="click()"
0
In your HTML, include the following code.
<script src="script.js"></script>
It works best when put at the very end of your <body>, just before you close it. Replace "script.js" with the pathname of your file (search pathname HTML src). If it is in the same folder, you can write it simply as I have done without the need to specify the path.
Now in the JavaScript file you can reference elements in your HTML (search DOM JavaScript). You use onclick="funct();" as an attribute to call a function from the JS file. Also, if you link another JS file to your HTML, you can use the same functions and variables across the different codes (to avoid this place all your code within a function).
0
i did what you told but it just doesn't work
0
How are your files saved? How are you referencing them for src=" "?
Could the problem be with your JS code not performing the action? Just write this on the first line of it and you'll know if the linking works.
document.body.innerHTML = "It works";
OR
alert("It works");
0
well i have html file named index.html
and java script file named script.js
both file are in same folder
i used script tag in the end of body tag
i wrote my function in script file
now i want call that function on my html file
i used on click event to call my function but it doesn'twork @ all
i watch the source view in browser the script file is bound to html file but i dont know why it doesn'twork
0
Sounds like you have linked it properly. The problem might be your JS or the way you have used onclick. See if the test I posted above works.
0
ah i am gonna get crazy
0
horay i found the real problem i should put these symbols ( ) after function name in event