mootools - Javascript Need to pull a value from a function within an array -


here code:

    <script> window.addevent('domready', function(){      new request.stocks({         stocks: ['sxcl'],         oncomplete: function(yahoo){             var result = '';             array.each(array.from(yahoo.query.results.quote), function(quote){ result += '<div class="company-ticks"></div> <span class="company">steel excel ({name})</span> <span class="sub-info"> - otc markets<span> </div>  <div><span class="value"> {lasttradepriceonly}</span><span class="changeup"> <img src="change-up.gif" class="change-img" />{change}  ({changeinpercent})</span></div></div>'.substitute(quote);             }, this);              $('stocks').set('html', result);         },         onrequest: function(script){             $('stocks').set('text', 'loading...');         }     }).send();      // request.stocks.element.js   });  </script> 

you see have variable {change]. need determine if variable positive or negative value. if positive should display class "changeup" , image change-up.gif. if value negative class displayed should "changedown" , image change-down.gif

the images green arrow , red arrow down. classes make color altrenate between red , green.

because within array thats being called using function i'm not sure how go this. assume have split "result" 3 sections. section before, section sets class , image, , rest of result.

any appreciated.

this uses javascript mootools. it's pulling stock quote yahoo.

share|improve question

i made assumption change variable property of quote object. otherwise that's easy fix in code bellow.

array.each(array.from(yahoo.query.results.quote), function (quote) {     quote.changeimage = (quote.change > 0) ? 'change-up.gif' : 'change-down.gif';      result += '<div class="company-ticks"></div> <span class="company">steel excel ({name})</span> <span class="sub-info"> - otc markets<span> </div>  <div><span class="value"> {lasttradepriceonly}</span><span class="changeup"> <img src="{changeimage}" class="change-img" />{change}  ({changeinpercent})</span></div></div>'.substitute(quote); }, this); 

please note, producing html in doing bit risky , hard maintain.

share|improve answer

your answer

 
discard

posting answer, agree privacy policy , terms of service.

not answer you're looking for? browse other questions tagged or ask own question.

Comments