Reputation: 14950
Good day!
Why is it that when I make the following javascript code external, some codes doesn't work
<form name="Keypad" action="">
</form>
var FKeyPad = document.Keypad; // DOESN'T WORK ANYMORE
var Accumulate = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num) {
if (FlagNewNum) {
FKeyPad.ReadOut.value = Num;
FlagNewNum = false;
}
else {
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
}
}
How can I make it work?
Thank you,
Upvotes: 0
Views: 346
Reputation: 22156
Include your external JS file just before </body>
tag and should work.
Upvotes: 1
Reputation: 700152
It has nothing to do with the code being external, it's all about when the code is executed.
You have to execute the code after the element has been created. You can put the script tag below the element in the code, or you can put the code in the handler for the window.onload
event to make it run after the page has loaded:
window.onload = function() {
// your code here
};
Upvotes: 2
Reputation: 2371
I can't find any sources which mention document.Keypad. I don't think it's supported by normal browsers.
Upvotes: 1