Echo a php function in a javascript -
i have following javascript
function showit(item,i,j,max){ var id; actualitem=item; for(var x=1;x<=i;x++){ id=item+"_"+x; document.getelementbyid(id).src="<?= suburl(); ?>/b.gif"; } for(var x=i+1;x<=max;x++){ id=item+"_"+x; if(x<=j) document.getelementbyid(id).src="<?= suburl(); ?>/y.gif"; else document.getelementbyid(id).src="<?= suburl(); ?>/w.gif"; } }
i have tried <?= suburl(); ?>
, <?php echo suburl(); ?>
function suburl(); looks this:
function suburl() { $suburl = 'http://localhost/www.site.com/static'; echo $suburl; }
and it's not working on echoing in javascript. appears pure html. it's appreciated thank you.
you try this:
function showit(item,i,j,max){ var id; actualitem=item; var url = suburl(); //this new for(var x=1;x<=i;x++){ id=item+"_"+x; document.getelementbyid(id).src=url+"/b.gif"; } for(var x=i+1;x<=max;x++){ id=item+"_"+x; if(x<=j) document.getelementbyid(id).src=url+"/y.gif"; else document.getelementbyid(id).src=url+"/w.gif"; } } function suburl() { var suburl = 'http://localhost/www.site.com/static'; return suburl; }
Comments
Post a Comment