Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript value to be printed in html

Status
Not open for further replies.

newbie14

Technical User
Feb 14, 2009
81
0
0
MY
Dear All,
I have a javascript variable which I need to print in html now? So how can I do this ? Can I put in some label etc? Thank you.
 
Can you provide some more information ?

You could just use document.write(myVar) to print it out, or you could use the DOM to update an element such as a DIV/SPAN etc

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
Dear Griffit,
For example I have function getData() and in that a simple variable which I get based on some calculation. So in my body I have stated where my poi variable should appear. Thank you.

<script defer="defer" type="text/javascript">
function getData()
{
var poi;
poi // is based on calculation and I will get this value then I want to see it in my html

}
</script>

<body>
<table>
<tr>
<td><font size="3" face="Calibri" ><b>Location:</b>//here is where i want poi value to appear</font></td>
</tr>
</table>

</body>
 
Where do you execute the function?

_________________
Bob Rashkin
 
Dear Bong,
I execute it on a button click. Thank you.
 
Dear Griffit,
Thank you for the link is it possible for me to control text size with Header I guess no rite. Is there any other alternative where I can control the text size and color too. Thank you.
 
Give your table cell an id and use that to output your variable.

Code:
<td id="cellid">...

Code:
document.getElementById('cellid').innerHTML=myvariable;

And Output whatever HTML you need with the value to modify it as you need to.

Code:
document.getElementById('cellid').innerHTML="<span style='color:#4455DD; border:2px inset #DDDDDD; background-color:#666666;'>" + myvariable + "</span>";




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top