Error in Code

Discussion in 'JavaScript' started by Weirfire, Jun 11, 2007.

  1. #1
    Can anyone see what the error is in the code below? My Javascript skills only stretch so far.

    <script type='text/javascript'>
    
    	function explodeArray(item,delimiter) { 
    		tempArray=new Array(1); 
    		var Count=0; 
    		var tempString=new String(item); 
    
    		while (tempString.indexof(delimiter)>0) { 
    			tempArray[Count]=tempString.substr(0,tempString.indexof(delimiter)); 
    			tempString=tempString.substr(tempString.indexof(delimiter)+1,tempString.length-tempString.indexof(delimiter)+1); 
    			Count=Count+1 
    		} 
    
    	tempArray[Count]=tempString; 
    	return tempArray; 
    	}
    
    	function get_filename(full_path) {
    
    		parts = explodeArray(full_path,'/');
    
    		var num_items = parts.length;
    
    		return parts[(num_items-1)];
    
    	}
    
    </script>
    Code (markup):
     
    Weirfire, Jun 11, 2007 IP
  2. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #2
    It would help if you'd post the error message you're getting...
     
    frankcow, Jun 11, 2007 IP
  3. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Code deleted.

    They come here looking for help, and then they disappear.

    I'll never understand it. Never.
     
    Mike H., Jun 11, 2007 IP
  4. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #4
    Are you talking about me?

    I live in the UK so I had to leave for home when it was time to go home. If I had stayed to wait for a reply the wife wouldn't have been too happy.

    Line: 12
    Char: 3
    Error Code : Object doesn't support this property or method
     
    Weirfire, Jun 12, 2007 IP
  5. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #5
    Hmm, looking at it briefly, I think all of your indexof's are supposed to be camel cased, like this: indexOf
     
    frankcow, Jun 12, 2007 IP
  6. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #6
    Thanks Frank. I'll give that a go.
     
    Weirfire, Jun 12, 2007 IP
  7. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #7
    Please find corrected code below
    
    <html>
    <head>
    
    <script type="text/javascript">
    
    	function explodeArray(item,delimiter) { 
    	 
    	
    		var tempString=new String(item); 
                    var tempString1 = new String();
    
    		if(tempString.lastIndexOf(delimiter)>0) { 
           
    			 tempString1 = 
    
    tempString.substr(tempString.lastIndexOf(delimiter)+1,tempString.length-tempString.lastIndexOf(delimiter)+1); 
                            
    	
    	return tempString1; 
    	}
    }
    function test(val) {
    alert(val);
    part=explodeArray(val,"/");
    }
    
    
    </script>
    </head>
    <body onload="test('a/b/c.htm')">
    hell
    </body>
    </html>
    
    Code (markup):
     
    it career, Jun 12, 2007 IP