Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Null or not an object! PLEASE HELP!

    This is a function to open a calculator in a new window. Everything loads fine and the new window opens with the tables and buttons for the calculator BUT I am having difficulty with an error saying "Fkeypad.Redout" - Null or not an object. Please help I am a fairly new to this.

    Message: 'FKeyPad.ReadOut' is null or not an object
    Line: 179
    Char: 1
    Code: 0
    URI: file://xvu-tor-fas/userhome_e$/alexander.consoli/Data/Scripts/FirstPage12-2.jsp


    <script>

    function openCalculator()
    {

    calcWindow=window.open('','','width=600,height=400');

    calcWindow.document.write("<p><center>Calculator</center></p></br>");

    calcWindow.document.write("<form name=input3 action=html_form_action.asp method=get></form> ");

    calcWindow.document.write("<CENTER><FORM name='Keypad' action=''><TABLE><B><TABLE border=2 width=50 height=60 cellpadding=1 cellspacing=5><TR><TD colspan=3 align=middle><input name='ReadOut' type='Text' size=24 value='0' width=100%></TD><TD</TD><TD><input name='btnClear' type='Button' value=' C ' onclick='Clear()'></TD><TD><input name='btnClearEntry' type='Button' value=' CE ' onclick='ClearEntry()'></TD></TR><TR><TD><input name='btnSeven' type='Button' value=' 7 ' onclick='NumPressed(7)'></TD><TD><input name='btnEight' type='Button' value=' 8 ' onclick='NumPressed(8)'></TD><TD><input name='btnNine' type='Button' value=' 9 ' onclick='NumPressed(9)'></TD><TD></TD><TD><input name='btnNeg' type='Button' value=' +/- ' onclick='Neg()'></TD><TD><input name='btnPercent' type='Button' value=' % ' onclick='Percent()'></TD></TR><TR><TD><input name='btnFour' type='Button' value=' 4 ' onclick='NumPressed(4)'></TD><TD><input name='btnFive' type='Button' value=' 5 ' onclick='NumPressed(5)'></TD><TD><input name='btnSix' type='Button' value=' 6 ' onclick='NumPressed(6)'></TD><TD></TD><TD align=middle><input name='btnPlus' type='Button' value=' + ' onclick='Operation('+')'></TD><TD align=middle><input name='btnMinus' type='Button' value=' - ' onclick='Operation('-')'</TD></TR><TR><TD><input name='btnOne' type='Button' value=' 1 ' onclick='NumPressed(1)'></TD><TD><input name='btnTwo' type='Button' value=' 2 ' onclick='NumPressed(2)'></TD><TD><input name='btnThree' type='Button' value=' 3 ' onclick='NumPressed(3)'></TD><TD></TD><TD align=middle><input name='btnMultiply' type='Button' value=' * ' onclick='Operation('*')'></TD><TD align=middle><input name='btnDivide' type='Button' value=' / ' onclick='Operation('/')'></TD></TR><TR><TD><input name='btnZero' type='Button' value=' 0 ' onclick='NumPressed(0)'></TD><TD><input name='btnDecimal' type='Button' value=' . ' onclick='Decimal()'></TD><TD colspan=3></TD><TD><input name='btnEquals' type='Button' value=' = ' onclick='Operation('=')'></TD></TR></TABLE></TABLE></B></FORM></CENTER><font face='Verdana, Arial, Helvetica' size=2>");

    calcWindow.focus();



    var FKeyPad = document.Keypad;
    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") <--THIS IS WHERE THE ERROR IS GENERATED
    FKeyPad.ReadOut.value = Num;
    else
    FKeyPad.ReadOut.value += Num;
    }
    }
    function Operation (Op) {
    var Readout = FKeyPad.ReadOut.value;
    if (FlagNewNum && PendingOp != "=");
    else
    {
    FlagNewNum = true;
    if ( '+' == PendingOp )
    Accumulate += parseFloat(Readout);
    else if ( '-' == PendingOp )
    Accumulate -= parseFloat(Readout);
    else if ( '/' == PendingOp )
    Accumulate /= parseFloat(Readout);
    else if ( '*' == PendingOp )
    Accumulate *= parseFloat(Readout);
    else
    Accumulate = parseFloat(Readout);
    FKeyPad.ReadOut.value = Accumulate;
    PendingOp = Op;
    }
    }
    function Decimal () {
    var curReadOut = FKeyPad.ReadOut.value;
    if (FlagNewNum) {
    curReadOut = "0.";
    FlagNewNum = false;
    }
    else
    {
    if (curReadOut.indexOf(".") == -1)
    curReadOut += ".";
    }
    FKeyPad.ReadOut.value = curReadOut;
    }
    function ClearEntry () {
    FKeyPad.ReadOut.value = "0";
    FlagNewNum = true;
    }
    function Clear () {
    Accumulate = 0;
    PendingOp = "";
    ClearEntry();
    }
    function Neg () {
    FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
    }
    function Percent () {
    FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accumulate);
    }
    function start1()
    {
    var FKeyPad = document.Keypad;
    var Accumulate = 0;
    var FlagNewNum = false;
    var PendingOp = "";
    NumPressed();
    Operation(Op);
    Decimal();
    ClearEntry();
    Clear();
    Neg();
    Percent();
    }
    calcWindow.onload = start1();
    }
    </script>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,550
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    Ugly ugly ugly.

    WHY would you use document.write() to create all that?

    Anyway, it's obvious why it won't work: You are creating the calculator, including <form name="Keypad">, in a SEPARATE WINDOW!

    Do then document.Keypad *DOES NOT EXIST* in the current wndow!

    Pardon me, but this entire effor is just very very wrong headed.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •