javascript - Replace td by image depending on value -
i'm working on project using smarty. want display results of array on web page, , replace '1' results image, , '0' results another. can far results want need replacement , don't know if it's possible , if is, how manage it. here's part of php code:
for ($c=0; $c<count($alpo); $c++){ $apg['p_i'] = $alpo[$c]['p_i']; $apg['p_l'] = $alpo[$c]['p_l']; $sga = $alpo[$c]['p_g_a']; ($i=0; $i<count($agid); $i++){ if (strpos($sga , $agid[$i]) !== false){ $sgid = $agid[$i]; $apg[$ag[$sgid ]] = '1'; } else{ $sgid = $agid[$i]; $apg[$ag[$sgid ]] = '0'; } } array_push($apo, $apg); unset($apg);
}
$smarty->assign("alpo", $apo);
and part of .tpl code (html/smarty)
... <div id="display_table_produit_gammes"> <table cellpadding=0 cellspacing=0 class="tbl_datas" id="table_produit" > {if $inbproduitsoptions == 0} <thead> <tr><th></th></tr> </thead> {else} <thead> <tr> <th width='8%'>id</th> <th width='10%'>p_l</th> {foreach from=$alg item=g name=lst} <th>{$g.g_l} ({$g.g_i})</th> {/foreach} </tr> </thead> <tbody> {foreach from=$alpo item=p name=lst} <tr> {foreach from=$p item=pval} <td>{$pval}</td> {/foreach} </tr> {/foreach} </tbody> {/if} </table> </div>
the results need change in tag, since dynamically charged i'm bit confused on way deal with.
thanks in advance , feel free ask me more informations if need (since i'm not english can hard understand purpose of topic hope it's clear enough)
here better explained answer: in smarty can use:
{if $pval eq '0'} <img src="image0.jpg"> {else} <img src="image0.jpg"> {/if}
if using javascript can write:
{foreach from=$p item=pval} <td class="replace_this_{$pval}"></td> {/foreach}
in order add class td , in javascript:
// select elements: var elems = document.getelementsbyclassname("replace_this_0"); // replace <td></td> <td><img src="image0.jpg"></td> for(var i= 0; i< elems.length; ++i) { elems[i].innerhtml = "<img src='image0.jpg'>"; }
and same second image. hope helps.
Comments
Post a Comment