Jump to content

Displaying Variables in a Table


Guest RCugs

Recommended Posts

I new to java script so i need a little help. Im simply trying to display variables in cells of a table. This is what iv'e tried so far.Attempt 1

var Winner = "You!";document.write("<tr><td>" + Winner + "</td><tr>");

Attempt 2

var Winner = "You!";<tr><td>	<script>document.write(Winner)</script> </td><td>

Attempt 3

var Winner = document.getElementById('Winner);Winner.style.innerHTML = "you";  //wasn't sure so i tried both.Winner.style.innerText = "You";<tr><td id="Winner"></td></tr>

Basically I want it to produce this.<tr><td>You</td></tr>I don't know why these arn't working.Again, Im new to this so I dont know if im close or way off but I've been working on it FOREVER and I cant get it. Someone please help! Thanks!

Link to comment
Share on other sites

How about something like this:HTML

<table cellspacing="0" cellpadding="0" border="0">  <tr><td><div id="WinnerCell" /></td></tr></table>

Javascript

var winner = "You!";var cell = document.getElementById("WinnerCell");cell.innerHTML = winner;

Your attempt #3 might have worked if you'd tried:

var Winner = document.getElementById('Winner);Winner.innerHTML = "You!";

Hope this helps!

Link to comment
Share on other sites

How about something like this:HTML
<table cellspacing="0" cellpadding="0" border="0">  <tr><td><div id="WinnerCell" /></td></tr></table>

Javascript

var winner = "You!";var cell = document.getElementById("WinnerCell");cell.innerHTML = winner;

Your attempt #3 might have worked if you'd tried:

var Winner = document.getElementById('Winner);Winner.innerHTML = "You!";

Hope this helps!

I'm hoping someone can give me a push in the right direction too!!!I have a random number generator that displays to "OutPut"... what I want to do is take the figure generated to "Output" and throw it to a case statement that loads an image. I have the output, I can write the case statement, but I am having major issues with the bit that goes in the middle!!!!!//startif (document.all)document.all.layer1.innerHTML=OutPut;if (document.getElementById)document.getElementById("layer1").innerHTML=OutPut;if (document.layers){ document.layers.layer1.document.open(); document.layers.layer1.document.write("<span style='position:absolute;top:0px;left:0px;font-family:Verdana;font-size:20px;color:#888888;text-align:center'>"+OutPut+"</span>"); document.layers.layer1.document.close(); } T=setTimeout('lotto()',20);//window.status=OutPut;}case 1: document.write(<caption>JACKPOT!!!!</caption><td><img src="dracula.jpg" width="1024" height="576" border="0" align="middle"></td> breakcan anyone tell me how to take Output and link to a case statement????????thanks in advance
Link to comment
Share on other sites

I'm not quite sure what you're going for there, but maybe this'll help (I haven't tested this, but it should be close):

<div id="caption" /><img id="display" align="middle" /><script type="text/javascript">// do whatever code you do to generate the random number// and/or recieve user input.var someNumber = 1;  // you would have your code assign some value herevar captionObj = document.getElementById("caption");var displayObj = document.getElementById("display");switch(someNumber){    case 1:  // someNumber == 1        captionObj.innerHTML = "JACKPOT!";        displayObj.src = "dracula.jpg";        displayObj.width = "1024";        displayObj.height = "576";        displayObj.alt = "JACKPOT!";        displayObj.border = "0";        break;    case 2:  // someNumber == 2        break;    default:        break;}</script>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...