Hi, I have the following code in a html document: <script type="text/javascript/> function [B]something123[/B]() { var [B]clickurl[/B] = response.getElementsByTagName('clickurl')[0].firstChild.nodeValue; var [B]imgsrc[/B] = response.getElementsByTagName('imgsrc')[0].firstChild.nodeValue; document.getElementById("click").innerHTML = clickurl + imgsrc; } </script> Code (markup): And it works perfect, but then I try to call in another part of the html document the following code: <script type="text/javascript/> document.write([B]clickurl[/B]); document.write([B]imgsrc[/B]); </script> Code (markup): I try to print the variables generated by something123, but it doesn't print anything and I get the following error: imgsrc is not defined - clickurl is not defined Any help on how can I print variables generated by a function after the function was executed? Thanks in advanced
You can define and globalize the variable outside the function using var, and modify it inside the function. <script type="text/javascript"> var clickurl; var imgsrc; function something123() { clickurl = response.getElementsByTagName('clickurl')[0].firstChild.nodeValue; imgsrc = response.getElementsByTagName('imgsrc')[0].firstChild.nodeValue; document.getElementById("click").innerHTML = clickurl + imgsrc; } </script> Code (javascript): Should work.