Domanda

Here's the script I use to query google finance, it brings back some stocks with a period in the ticker, I need to replace that with a dash for finviz.com, but for some reason this is causing me a lot of grief. Every other ticker works on hover except for that one MOG-A. Just gives me 'missing ; before statement' error with no details.

( function($) {
$(document).ready(function(){

  $.getJSON('https://finance.google.com/finance/info?client=ig&q='+stocklist+'&    callback=?',function(response){
for (var i = 0; i < response.length; i++) {
    var stockInfo = response[i];
    if (stockInfo.c.indexOf("-") != -1) {var scolor = "red";} else {var scolor =     "green";}
    var finvizt = stockInfo.t.replace('\.','\-');
    var stockString ='<div style="width:210px;position:relative;"     class="stockWrapper">';
    stockString +='<span class="stockPrice" style="margin-left:-10px"><a class="slink"     name="slink'+stockInfo.t+'" href="http://finviz.com    /quote.ashx?t='+finvizt+'" onMouseOver="var         newimg'+stockInfo.t+'=img_create(\''+escape(stockInfo.t)+'    \');slink=getElementById(\'slink'+stockInfo.t+'\');thelink=this;var arx=getPos(thelink);     var posx=arx[0]+90;var posy=arx[1]-75;var         x=document.getElementById(\'stock'+stockInfo.t+'\');x.style.position=\'absolute    \';x.style.display=\'block\';x.style.left=posx+\'px\';x.style.top=posy+\'px\';"     onMouseOut="document.getElementById(\'stock'+stockInfo.t+'\').style.display=\'none\';"     target="external">'+stockInfo.t+'</a></span>';
    stockString +='<span class="stockPrice" style="position:absolute;right:120px"     title="'+stockInfo.ltt+'">'+stockInfo.l+'  </span>';
    stockString +='<span class="stockChange" style="color:'+scolor+';position:absolute;    right:75px">'+stockInfo.c+'</span>';
    stockString +='<span class="stockChange" style="color:'+scolor+';position:absolute;    right:25px">'+stockInfo.cp+'%</span>';
    stockString +='</div>';
    $('.stockTick').prepend(stockString);
    }
  });

});
 } ) ( jQuery );

Then there's the code I use for the image

function img_create(alt) {
    if (!(document.getElementById('stock'+unescape(alt))))
    {
    var img= document.createElement('img');
    img.src= 'http://finviz.com/chart.ashx?s=m&p=d&t='+unescape(alt).replace('.','-');
    img.id= 'stock'+unescape(alt);
    img.cssText= 'display:none;position:absolute;';
    img.style.border= '1px solid #000';
    img.style.zIndex='99';
    document.body.appendChild(img);
    return img;
    }
}

All the escape, unescape stuff was added as a means to try to fix it with no luck. I realize the code is messy, any help is appreciated.

Example page with the portfolio tickers on the left, MOG.A (MOG-A in finviz) is the real piece of work. http://mimictrading.com/viewtopic.php?f=5&t=298

È stato utile?

Soluzione

The problem is in the inline Javascript in the onmouseover attribute:

<a class="slink" 
   name="slinkMOG.A" 
   href="http://finviz.com/quote.ashx?t=MOG-A" 
   onmouseover="var newimgMOG.A=img_create('MOG.A');slink=getElementById('slinkMOG.A');thelink=this;var arx=getPos(thelink); var posx=arx[0]+90;var posy=arx[1]-75;var x=document.getElementById('stockMOG.A');x.style.position='absolute';x.style.display='block';x.style.left=posx+'px';x.style.top=posy+'px';" onmouseout="document.getElementById('stockMOG.A').style.display='none';"
   target="external">MOG.A</a>

The statement var newimgMOG.A = img_create('MOG.A'); is not valid, because you can't have a . in a variable name.

It looks to me like the variable name is never used, so you can change that to just img_create('MOG.A').

This is coming from viewtopic.php, not Javascript.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top