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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Keep getting object is null/ not object error

    Code:
    <P>
    
    <center>
    
    <font color="black" size="2px">
    
    Please enter the number of rows you want for your 
    
    table:
    
    <br>
    
    <form name="rows">
    
    <input type="text" name="cellNumber" size=6>
    
    </form>
    
    </font>
    </center>
    </p>
    <BR>
    I am basically modifying Mr. J's costume made confirm box to include a text field. At any rate, the confirmed box will be activated by one function, a function that basically alters the visiability status of the confirmed box. Once the confirm box pops up, the visitor has the option of typing something, and then clicking send. My aim is to see if i understand the idea of control flow.

    At any rate, here's the function that is activated, when the send button is clicked:

    Code:
    <script language="JavaScript1.2">
    
    var rowsTotal;
    
    function numbOfRows(){
    
    var rowNumb=document.forms.rows.cellNumber;
    
    if(rowNumb.value!=-1){
    alert("You typed " + rowNumb.value + "\n");
      }
    else{
    alert("You have left the field blank!");
      }
    }
    
    rowsTotal = numbOfRows();
    
    </script>
    At any rate, i keep getting an error message.
    LovesWar

  • #2
    New Coder
    Join Date
    Oct 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are calling the function before the element exists. Move the script below the markup, or define the variable onload.
    . We are, in a nutshell.

  • #3
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How can that be, since i am calling the function long after the page has loaded? When the page loads, i have a menu with a few buttons. On one of the buttons, i click, and the costume confirm box is launched. As i said before, on that confirm box, there is a type field. A number is supposed to be typed. once typed, the visitor is supposed to hit a button that says, "Send." Once the button is clicked, the confirm box is supposed to disappear. From the point forward, i can hit another button, and alert what was typed in.

    If i use an onload, then i wont be able to control when the confirm box appears. I do not want the confirm box to appear the minute the page loads. I want it to appear, after the page loads.

    Code:
    <html>
    
    <head>
    
    <title>  Table_Creator </title>
    
    <style>
    
    .controlpanel {position:absolute;top:70px;left:40px;
             width:60px;height:250px;
    	 background-color:teal;padding:10px;}
    
    .butt{width:75px;height:20px;text-align:center;font-size:14px;vertical-align:center;color:#b2a682;border:1px solid #d4c8b4; background:#9f9573;cursor:hand}
    
    
    .buttover{width:75px; height:20px;text-align:center;font-size:14px;vertical-align:center;color:#ffffff;border:1px solid #b2a682; background:#c9bda9;cursor:hand}
    
    
    .buttdown{width:75px; height:20px;text-align:center;font-size:14px;vertical-align:center;color:#404000;border:1px solid #908460; background:#9f9573;cursor:hand}
    </style> 
    
    
    </head>
    
    <body>
    <br>
    <script language="JavaScript1.2">
    <!--
    /*Credit JavaScript Kit www.javascriptkit.com*/
    
    var dragapproved=false
    var z,x,y
    
    function move(){
    if (event.button==1 && dragapproved){
    z.style.pixelLeft=temp1+event.clientX-x
    z.style.pixelTop=temp2+event.clientY-y
    return false
    }
    }
    
    
    function drags(){
    if (!document.all)
    return
    if (event.srcElement.className=="drag"){
    dragapproved=true
    z=event.srcElement
    temp1=z.style.pixelLeft
    temp2=z.style.pixelTop
    x=event.clientX
    y=event.clientY
    document.onmousemove=move
    }
    }
    document.onmousedown=drags
    document.onmouseup=new Function("dragapproved=false")
    //-->
    </script>
    
    <script>
    <!--
    
    function showHide(layerid){
    if (document.getElementById(layerid).style.visibility != "hidden"){
    document.getElementById(layerid).style.visibility = "hidden";
    }else{
    document.getElementById(layerid).style.visibility = "visible";
    }
    }
    
    function function1(){
    alert("This calls a function or whatever")
    }
    //-->
    </script>
    
    <script language="JavaScript1.2">
    
    var rowsTotal;
    
    function numbOfRows(){
    
    var rowNumb=document.forms.['rows']['cellNumber'];
    
    if(rowNumb.value!=-1){
    alert("You typed " + rowNumb.value + "\n");
      }
    else{
    alert("You have left the field blank!");
      }
    }
    
    rowsTotal = numbOfRows();
    
    </script>
    
    <script language="JavaScript1.2">
    
    function testOne(){
    
    alert("Hello!.  I am function \"testOne!\"");
    
    }
    
    function testTwo(){
    
    alert("Hello!.  I am function \"testTwo!\"");
    
    }
    
    </script>
    
    </HEAD>
    
    
    <BODY bgcolor="red">
    
    
    
    <div class="controlpanel">
    
    
    <form name="frm_A">
    <input type="button" value="Show Dialogue" name="bttn_B" onClick="showHide('conFirm');">
    <br>
    
    
    <input type="button" value="Total Rows" name="bttn_C" onClick="numbOfRows();">
    <br>
    
    
    <input type="button" value="Potential Button" name="bttn_C" onClick="testOne();">
    <br>
    
    <input type="button" value="Potential Button" name="bttn_C" onClick="testTwo();">
    <br>
    </form>
    
    </div>
    
    
    <DIV id="conFirm" class="drag" style="position:absolute;left:300px;top:120px; width:250px;color:#FFFFFF;font-weight:bold;color:#FFFFFF;border-top:2px solid #ffffff; border-left:2px solid #ffffff; border-right:2px solid #808080; border-bottom:2px solid #808080; background:#c9bda9;visibility:hidden;z-index:5">
    
    
    <div style="height:20px;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#FF9f9573', EndColorStr='#FFc9bda9';padding:5px;)">
    
    Number of Rows:</div>
    
    
    <P>
    
    <center>
    
    <font color="black" size="2px">
    
    Please enter the number of rows you want for your table:
    
    <br>
    <form name="rows">
    <input type="text" name="cellNumber" size=6>
    </form>
    
    </font>
    </center>
    </p>
    <BR>
    
    
    <div style="position:absolute;left:30px;top:130px" class="butt" onmouseover="this.className='buttover'" onmousedown="this.className='buttdown'" onmouseup="this.className='buttover'" onmouseout="this.className='butt'" onclick="showHide('conFirm')">Send</div>
    
    
    <div style="position:absolute;left:135px;top:130px" class="butt" onmouseover="this.className='buttover'" onmousedown="this.className='buttdown'" onmouseup="this.className='buttover'" onmouseout="this.className='butt'" onclick="showHide('conFirm')">Cancel</div>
    <BR>
    
    </DIV>
    
    </body>
    
    </html>
    Again, before some rude retro ape charges me with plagiarism, the above is a slight modification of a script by Mr. J. The link i think is,

    http://www.huntingground.freeserve.c...le/alert.htm&2

    That to my opinion is where the costume confirm box first appeared to me.
    LovesWar

  • #4
    New Coder
    Join Date
    Oct 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I told you why the error is occurring.

    Another error in your syntax is: forms.['rows'] --remove the dot.
    Last edited by posinot; 10-31-2004 at 06:33 AM. Reason: terminology
    . We are, in a nutshell.

  • #5
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I told you why the error is occurring.
    Yes you did, but i also said that couldnt be. Have you even checked my code? Do you even know what is involved?

    Another error in your syntax is: forms.['rows'] --remove the dot.
    Yes, i removed that too, but somehow i keep running into errors.

    You are calling the function before the element exists. Move the script below the markup, or define the variable onload.
    How do i define a variable on onload? And which script am i supposed to move to the bottom of the page?

    This doesnt make any sense. The form is in a div tag that acts as a custom confirm box. The visiability of the custom confirm box is altered by the press of a button. How can the form not exist at the time i press the button to alter the visiability status? It doesnt make sense to me.
    LovesWar

  • #6
    New Coder
    Join Date
    Oct 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What do you suppose this line does?
    rowsTotal = numbOfRows();
    . We are, in a nutshell.

  • #7
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    You need to change the relevant line in the numbOfRows() function to this :

    var rowNumb=document.forms['rows'].cellNumber;

    Then comment out this line :

    rowsTotal = numbOfRows();

    like this:

    //rowsTotal = numbOfRows();

  • #8
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    from posinot:

    What do you suppose this line does?
    rowsTotal = numbOfRows();
    I thought i was storing the value of the function in the variable?

    Should i be using a return statement? And if so, do i just say, return? Or i should be returning a variable within the function? Never really did fully understand the return statement.
    LovesWar

  • #9
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    from Puffin The Erb:

    You need to change the relevant line in the numbOfRows() function to this :

    var rowNumb=document.forms['rows'].cellNumber;

    Then comment out this line :

    rowsTotal = numbOfRows();

    like this:

    //rowsTotal = numbOfRows();
    I have done all of the above. i am "now" getting error "Object expected", line 116, char 1.

    I am not winning here.

    Take a look:

    Code:
    <script language="text/javascript">
    
    var rowsTotal="";
    
    function numbOfRows(){
    
    var rowNumb=document.forms['aunt'].uncle;
    
    if(rowNumb.value!=-1){
    alert("You typed " + rowNumb.value + "\n");
    rowNumb.value="";
    }
    else{
    alert("You have left the field blank!");
      }
    }
    
    //rowsTotal = numbOfRows();
    function showDataTyped(){
    alert(rowsTotal);
    }
    </script>
    Then there is this part:

    Code:
    <div style="position:absolute;left:30px;top:130px" class="butt" onmouseover="this.className='buttover'" onmousedown="this.className='buttdown'" onmouseup="this.className='buttover'" onmouseout="this.className='butt'" onclick="numbOfRows();">  Send </div>
    Somehow, somewhere, the error refers specifically this part of the code. I only get it, when i hit the send button. Nowhere else, do i as of yet, get any other errors.

    Is there a trick to making the cursor jump to the suggested line of code? I have no idea how it counts lines. Would make coding easier, if i knew where exactly the line it refers to was.
    LovesWar

  • #10
    New Coder
    Join Date
    Oct 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, you'd need a return statement in the function for that sort of reference to work (the variable would be assigned the return value).

    To find the error line# in Notepad.exe, uncheck Word Wrap from the Format menu, then go to the
    Edit menu, click Go To, enter the line#, and click OK.
    . We are, in a nutshell.

  • #11
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As usual, no resolution has been found. As i had suspected, the line 116 was precisely at the point i thought it was. I did what you said. I unchecked word wrap, then went to Edit, and from it, i chose go to. In the prompt box, i typed the line number, and still, i examined the line, and i still do not know what object i am supposed to be making sure that it exists.

    Thankz for the Go To Command. It will save me a lot of hair pulling when i scan for errors.
    LovesWar

  • #12
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SpiritualStorms
    Again, before some rude retro ape charges me with plagiarism, the above is a slight modification of a script by Mr. J.
    Yeah, I hear you... You need to watch those rude retro apes!! It is my understanding that they often irreparably harm the tender psyche of thin skinned little sissies....



    .....Willy

  • #13
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    LOL. Now theres the Willy i once knew, and loved to hate. Welcome back, you ole fart.

    Seriously, though, the null business is really putting miles on my age-ometer. Knows that i mean?
    LovesWar

  • #14
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Your code has changed since the original post.
    Adapting your original post worked for me.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Original</title>
    <style>

    .controlpanel {position:absolute;top:70px;left:40px;
    width:60px;height:250px;
    background-color:teal;padding:10px;}

    .butt{width:75px;height:20px;text-align:center;font-size:14px;vertical-align:center;color:#b2a682;border:1px solid #d4c8b4; background:#9f9573;cursor:hand}

    .buttover{width:75px; height:20px;text-align:center;font-size:14px;vertical-align:center;color:#ffffff;border:1px solid #b2a682; background:#c9bda9;cursor:hand}

    .buttdown{width:75px; height:20px;text-align:center;font-size:14px;vertical-align:center;color:#404000;border:1px solid #908460; background:#9f9573;cursor:hand}
    </style>

    </head>
    <body>
    <br>
    <script language="JavaScript1.2">
    <!--
    /*Credit JavaScript Kit www.javascriptkit.com*/

    var dragapproved=false
    var z,x,y

    function move(){
    if (event.button==1 && dragapproved){
    z.style.pixelLeft=temp1+event.clientX-x
    z.style.pixelTop=temp2+event.clientY-y
    return false
    }
    }


    function drags(){
    if (!document.all)
    return
    if (event.srcElement.className=="drag"){
    dragapproved=true
    z=event.srcElement
    temp1=z.style.pixelLeft
    temp2=z.style.pixelTop
    x=event.clientX
    y=event.clientY
    document.onmousemove=move
    }
    }
    document.onmousedown=drags
    document.onmouseup=new Function("dragapproved=false")
    //-->
    </script>

    <script>
    <!--

    function showHide(layerid){
    if (document.getElementById(layerid).style.visibility != "hidden"){
    document.getElementById(layerid).style.visibility = "hidden";
    }else{
    document.getElementById(layerid).style.visibility = "visible";
    }
    }

    function function1(){
    alert("This calls a function or whatever")
    }
    //-->
    </script>

    <script language="JavaScript1.2">

    var rowsTotal;

    function numbOfRows(){

    var rowNumb=document.forms['rows'].cellNumber;

    if(rowNumb.value!=-1){
    alert("You typed " + rowNumb.value + "\n");
    }
    else{
    alert("You have left the field blank!");
    }
    }

    //rowsTotal = numbOfRows();

    </script>

    <script language="JavaScript1.2">

    function testOne(){

    alert("Hello!. I am function \"testOne!\"");

    }

    function testTwo(){

    alert("Hello!. I am function \"testTwo!\"");

    }

    </script>
    </head>

    <body onLoad="rowsTotal">
    <html>

    <head>

    <title> Table_Creator </title>



    </head>


    <body bgcolor="red">
    <div class="controlpanel">
    <form name="frm_A">
    <input type="button" value="Show Dialogue" name="bttn_B" onClick="showHide('conFirm');">
    <br>
    <input type="button" value="Total Rows" name="bttn_C" onClick="numbOfRows();">
    <br>
    <input type="button" value="Potential Button" name="bttn_C" onClick="testOne();">
    <br>

    <input type="button" value="Potential Button" name="bttn_C" onClick="testTwo();">
    <br>
    </form>
    </div>
    <div id="conFirm" class="drag" style="position:absolute;left:300px;top:120px; width:250px;color:#FFFFFF;font-weight:bold;color:#FFFFFF;border-top:2px solid #ffffff; border-left:2px solid #ffffff; border-right:2px solid #808080; border-bottom:2px solid #808080; background:#c9bda9;visibility:hidden;z-index:5">
    <div style="height:20px;filterrogidXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#FF9f9573', EndColorStr='#FFc9bda9';padding:5px">
    Number of Rows:</div>
    <p>
    <center>
    <font color="black" size="2px">
    Please enter the number of rows you want for your table:
    <br>
    <form name="rows">
    <input type="text" name="cellNumber" size=6>
    </form>
    </font>
    </center>
    </p>
    <br>
    <div style="position:absolute;left:30px;top:130px" class="butt" onmouseover="this.className='buttover'" onmousedown="this.className='buttdown'" onmouseup="this.className='buttover'" onmouseout="this.className='butt'" onclick="showHide('conFirm')">Send</div>
    <div style="position:absolute;left:135px;top:130px" class="butt" onmouseover="this.className='buttover'" onmousedown="this.className='buttdown'" onmouseup="this.className='buttover'" onmouseout="this.className='butt'" onclick="showHide('conFirm')">Cancel</div>
    <br>
    </div>
    </body>
    </html>

  • #15
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, i am suprised, considering the fact that there is like more than one closing head tag in the whole code.

    At any event, i tweak, in the hopes of hitting the answer, but generally to no avail. I swear, the time i have spent learning JavaScript has taken away from learning something a bit more practical, like Java, or Perl.
    LovesWar


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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