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 10 of 10
  1. #1
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts

    Error: array.splice is not a function, and more big fun

    First, I'm experiencing an AgGrAvAtInG error on the following page: http://www.mediamogulsweb.com/client...stingHTML.html

    Error: cat[u].splice is not a function
    The relevant code, with the line of code that is triggering the error in red:

    Code:
    function processGetPost2()
    {
    	var myajax = ajaxpack.ajaxobj;
    
    	if (myajax.readyState == 4)
    	{
    		// if request of file completed
    
    		if (myajax.status == 200 || window.location.href.indexOf("http") == -1)
    		{
    			// if request was successful or running script locally
    			// Update catalog code here
    
    			var dataNew2 = myajax.responseText;
    			var arrKey2 = parseInt(dataNew2) - 1;
    	 		
    	 		var h = 0;
    	 		for (u=0; u<catNameArray.length; u++)
    			{
    				if (cat[u] == sortBy)
    					h = 1;
    				
    				cat[u].splice(arrKey2,1);
    				
    				tt = 0;
    				for (var w in cat[u])
    				{
    					cat[u][tt].childNodes[0].nodeValue = cat[u][w].childNodes[0].nodeValue;
    					tt++;
    				}
    					
    				if (h == 1)
    				{
    					sortBy = cat[u];
    					h = 0;
    				}
    			}
    			
    			if (cat[0].length == 0)
    			{
    				alert('The catalog is empty!');
    				return false;
    			}
    	 		
    	 		if (matches.length > 0)
    	 		{
    	 			if (matches.length > recsPerPage)
    	 			{
    	 				if ((matches.length - 1) % recsPerPage == 0)
    	 					currentSearchPage = currentPage - 1;
    	 			}
    
    				searchXML(search_id);
    	 		}
    	 		else
    	 		{
    				records = sortRecords();
    				myPages = paginate();
    
    	 			if (records.length >= recsPerPage)
    	 			{
    	 				if (records.length % recsPerPage == 0)
    	 					currentPage -= 1;
    	 			}
    	 			
    	 			displayPage(currentPage,'yes');
    	 		}
    			
    			clearTimeout(timer);
    			
    			var childnode=document.getElementById('workingBox');
    			var removednode=document.getElementById('main_content').removeChild(childnode);
    		}
    		else
    		{
    			//alert('myajax.status='+myajax.status);
    		}
    	}
    	else
    	{
    		//alert('myajax.readyState='+myajax.readyState);
    	}
    }
    Any ideas? I feel like I've tried everything...

    Second (when the above problem is resolved), I'm also getting an error in the following code:

    Code:
    function popupBox()
    {
        window.onscroll = function()
        {
            if (window.pageYOffset)
                document.getElementById('workingBox').style.top = window.pageYOffset + 145 + 'px';    
            else if (document.documentElement.scrollTop)
                document.getElementById('workingBox').style.top = document.documentElement.scrollTop + 145 + 'px';                    
            else
                document.getElementById('workingBox').style.top = document.body.scrollTop + 145 + 'px';
        }
    
        timer = setTimeout('popupBox()',1000);
    }
    The error says something to the effect of:

    document.getElementById('workingBox') has no properties.
    The error is triggered when the scroll bar is used after a record is deleted. I used clearTimeout to clear the timer, so I can;t understand why the window.onscroll event continues to be triggered after I kill the timer (and presumably popupBox() stops executing recursively?)...

    I must be missing something here...

    Anyway, could use some help with both of these problems...thanks
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    is cat[u] an array?

    if you do alert(typeof cat[u]); what does it say?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts
    is cat[u] an array?

    if you do alert(typeof cat[u]); what does it say?
    cat[u] should be an object of type Array...

    when I execute the alert(), it returns "object".....

    how exactly do I interpret that?

    Does the script forget that cat[u] is an Array when returning from my PHP script?

    The array is initially created here onLoad:

    Code:
    function extractData()
     {
         var entiredoc = xmlDoc.documentElement;
         var docnodes = entiredoc.childNodes;
         parentNode = docnodes[1].tagName;    
         
         for (q=0; q<catNameArray.length; q++)
         {
             cat[q] = xmlDoc.getElementsByTagName(catNameArray[q]);
         }    
         
         showCatalog(cat[0],catNameArray[0]);
     }
    getElementsByTagName should return an array object? It is recognized as such everywhere else in my script, just not in this particular AJAx callback function...
    Last edited by chump2877; 12-12-2006 at 09:30 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #4
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually from what I read getElementsByTagName() does not return an array but an "array like" object.

    the difference is in the definition

    var arr = [];
    var arr_like = {};

    After that they are addressed similar

    arr[0] = 6;
    arr_like[0] = 6;

    unless you try and launch an array specific function.

    If you have JavaScript : The Definitive Guide check page 122.

    david_kw

  • #5
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts
    http://www.byteclub.net/wiki/index.p...mentsByTagName

    I assume that's what you are referring to....
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #6
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts
    well anyway that was worth the agony...NOT..lol

    thanks david AGAIN for steering me in the right direction...

    this modified code appears to allow me to operate on the HTMLcollection exactly like an array, as opposed to somewhat like an array (who invented these so-called "HTMLcollections"?!?....phhht):

    Code:
    function extractData()
    {
        var entiredoc = xmlDoc.documentElement;
        var docnodes = entiredoc.childNodes;
        parentNode = docnodes[1].tagName;    
        
        for (q=0; q<catNameArray.length; q++)
        {
            cat[q] = collectionToArray(xmlDoc.getElementsByTagName(catNameArray[q]));
        }    
        
        showCatalog(cat[0],catNameArray[0]);
    }
    
    // Convert HTMLCollection object to Array object
    
    function collectionToArray(col) 
    {
        a = new Array();
        for (i=0; i<col.length; i++)
            a[a.length] = col[i];
        return a;
    }
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #7
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts
    By the way, I still could use a hand with this, and now you can actually see the error for yourself:

    Second (when the above problem is resolved), I'm also getting an error in the following code:

    Code:
    function popupBox()
    {
        window.onscroll = function()
        {
            if (window.pageYOffset)
                document.getElementById('workingBox').style.top = window.pageYOffset + 145 + 'px';    
            else if (document.documentElement.scrollTop)
                document.getElementById('workingBox').style.top = document.documentElement.scrollTop + 145 + 'px';                    
            else
                document.getElementById('workingBox').style.top = document.body.scrollTop + 145 + 'px';
        }
    
        timer = setTimeout('popupBox()',1000);
    }
    The error says something to the effect of:

    document.getElementById('workingBox') has no properties.
    The error is triggered when the scroll bar is used after a record is deleted. I used clearTimeout to clear the timer, so I can;t understand why the window.onscroll event continues to be triggered after I kill the timer (and presumably popupBox() stops executing recursively?)...

    I must be missing something here...
    Last edited by chump2877; 12-12-2006 at 11:08 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #8
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Quote Originally Posted by chump2877 View Post
    this modified code appears to allow me to operate on the HTMLcollection exactly like an array, as opposed to somewhat like an array (who invented these so-called "HTMLcollections"?!?....phhht):
    I think they were invented because of a slew of different things they needed to do:
    - They're document structures, so the methods for array modifications can't work on them. Insertion, deletion, replacement, sorting, joining, folding, mapping can't work the same way as they do on arrays.
    - They're representations of live documents. If a document changes for any reason, they change as well.
    - They're effectively read only.
    - And of course, they're made to work from both JavaSript and Java, as well as other languages.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #9
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts
    I think they were invented because of a slew of different things they needed to do:
    - They're document structures, so the methods for array modifications can't work on them. Insertion, deletion, replacement, sorting, joining, folding, mapping can't work the same way as they do on arrays.
    - They're representations of live documents. If a document changes for any reason, they change as well.
    - They're effectively read only.
    - And of course, they're made to work from both JavaSript and Java, as well as other languages.
    I knew there was a reason! Well this would be nice, as quoted from http://www.byteclub.net/wiki/index.p...mentsByTagName

    "It would be nice if the collectionToArray function above could be added to HTMLCollection's prototype, however for some reason it is read-only."

    BTW, still need a little help with my second problem....Weeeeee...I'm silly...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #10
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts
    Nevermind, second problem has been resolved...thanks for everyone;s help...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪


  •  

    Posting Permissions

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