0

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,

4
  • document.Keypad? what's your dependency (js library)? Commented May 24, 2011 at 5:36
  • I'm calling the FORM I've created.... Commented May 24, 2011 at 5:37
  • opps. my bad :) and if you are mentioning to this article javascript.internet.com/math-related/advanced.html , would say lousy code. dont copy :) Commented May 24, 2011 at 5:43
  • if using jquery $(function (){...code...}) else onload event Commented May 24, 2011 at 5:46

3 Answers 3

2

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
};
Sign up to request clarification or add additional context in comments.

3 Comments

Where would i put the window.onload?
in my javascript external file or in my hmtl? Thank you
I would suggest using a library like Mootools or something. It will make life easier.
1

Include your external JS file just before </body> tag and should work.

Comments

1

I can't find any sources which mention document.Keypad. I don't think it's supported by normal browsers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.