JavaScript help for undefined object.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ncost
    New Member
    • Jan 2012
    • 7

    JavaScript help for undefined object.

    I have a blog template that I downloaded for use on my blogger account, and I was having some trouble with an undefined box that's supposed to display the date for each post. I'm more keen on HTML than JS, so I was wondering if anyone could help me with it. I attached a picture of the box in question, and here's the part of the code which I believe is the problem.

    function rp(json){docume nt.write('<ul>' );for(var i=0;i<numposts; i++){document.w rite('<li>');va r entry=json.feed .entry[i];var posttitle=entry .title.$t;var posturl;if(i==j son.feed.entry. length)break;fo r(var k=0;k<entry.lin k.length;k++){i f(entry.link[k].rel=='alternat e'){posturl=ent ry.link[k].href;break}}po sttitle=posttit le.link(posturl );var readmorelink="( more)";readmore link=readmoreli nk.link(posturl );var postdate=entry. published.$t;va r cdyear=postdate .substring(0,4) ;var cdmonth=postdat e.substring(5,7 );var cdday=postdate. substring(8,10) ;var monthnames=new Array();monthna mes[1]="Jan";monthnam es[2]="Feb";monthnam es[3]="Mar";monthnam es[4]="Apr";monthnam es[5]="May";monthnam es[6]="Jun";monthnam es[7]="Jul";monthnam es[8]="Aug";monthnam es[9]="Sep";monthnam es[10]="Oct";monthnam es[11]="Nov";monthnam es[12]="Dec";if("cont ent"in entry){var postcontent=ent ry.content.$t}e lse if("summary"in entry){var postcontent=ent ry.summary.$t}e lse var postcontent=""; var re=/<\S[^>]*>/g;postcontent=p ostcontent.repl ace(re,"");docu ment.write(post title);if(showp ostdate==true)d ocument.write(' - '+monthnames[parseInt(cdmont h,10)]+' '+cdday);if(sho wpostsummary==t rue){if(postcon tent.length<num chars){document .write(postcont ent)}else{postc ontent=postcont ent.substring(0 ,numchars);var quoteEnd=postco ntent.lastIndex Of(" ");postcontent= postcontent.sub string(0,quoteE nd);document.wr ite(postcontent +'...'+readmore link)}}document .write('</li>')}document. write('</ul>')}
    Attached Files
    Last edited by acoder; Jan 15 '12, 02:56 PM.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    how do call that function on the page? (this function has only very limited use)

    Comment

    • ncost
      New Member
      • Jan 2012
      • 7

      #3
      I'm not sure what it's called. The only info about the function that I could find was in the code above. If you like, I could attach the whole template HTML.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I only need the part of the HTML, where this function is in.

        PS. calling a function means to execute it. ex. <img src="…" onclick="doSome thing()"> or document.getEle mentById("test" ).onclick = doSomething;

        Comment

        • ncost
          New Member
          • Jan 2012
          • 7

          #5
          I looked all through and this is all I could find that might be relevant:

          Code:
          function removeHtmlTag(strx,chop){ 
          	if(strx.indexOf("<")!=-1)
          	{
          		var s = strx.split("<"); 
          		for(var i=0;i<s.length;i++){ 
          			if(s[i].indexOf(">")!=-1){ 
          				s[i] = s[i].substring(s[i].indexOf(">")+1,s[i].length); 
          			} 
          		} 
          		strx =  s.join(""); 
          	}
          	chop = (chop < strx.length-1) ? chop : strx.length-2; 
          	while(strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1) chop++; 
          	strx = strx.substring(0,chop-1); 
          	return strx+'...'; 
          }
          
          function createSummaryAndThumb(pID){
          	var div = document.getElementById(pID);
          	var imgtag = "";
          	var img = div.getElementsByTagName("img");
          	var summ = summary_noimg;
          	if(img.length>=1) {	
          		imgtag = '<span style="float:left; padding:0px 10px 5px 0px;"><img src="'+img[0].src+'" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></span>';
          		summ = summary_img;
          	}
          	
          	var summary = imgtag + '<div>' + removeHtmlTag(div.innerHTML,summ) + '</div>';
          	div.innerHTML = summary;
          }
          
          //]]>
          </script>
          Sorry if that isn't what you're looking for; I don't have too much of an eye for JS coding. If it helps, here's the rest of the template code in an attachment.
          Attached Files
          Last edited by Dormilich; Jan 15 '12, 08:11 PM. Reason: please use [CODE] [/CODE] tags when posting code

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            hm, I don’t see the rp() function used anywhere. do you have a live page by chance?

            Comment

            • ncost
              New Member
              • Jan 2012
              • 7

              #7
              Yup! It's kingdomeyes.blo gspot.com

              Comment

              • ncost
                New Member
                • Jan 2012
                • 7

                #8
                Oh, I just fixed it. Turned out it wasn't a JS problem, but a settings issue. Sorry for the trouble and thanks for the help!

                Comment

                Working...