PDA

View Full Version : Using JS to fill a cell


marie180
07-15-2002, 11:27 PM
On a previous thread I found the following code for putting a text label in a cell (depending on the button the user clicked)

<html>
<head>
<title>untitled</title>
<style type="text/css">

table {
width: 100px;
text-align: center;
padding: 3px;
border: 3px coral ridge;
background: tan;
}

td {
font: 600 14px "Comic Sans MS";
color: #660000;
}

input {
font: 200 12px "Comic Sans MS";
background: beige;
border-color: tomato;
}

body {
text-align: center;
margin-top: 100px;
background: black;
}

</style>
<script type="text/javascript" language="JavaScript">

function put(id, sContent) {
if (typeof document.getElementById != 'undefined' && sContent)
document.getElementById(id).innerHTML = sContent;
}

</script>
</head>
<body>
<table>
<tr>
<td id="cell1">cell 1</td>
</tr></table>
<br><br>
<form>
<input type="button" value="Tom" onclick="put('cell1',this.value)"><hr width="100">
<input type="button" value="Dick" onclick="put('cell1',this.value)"><hr width="100">
<input type="button" value="Harry" onclick="put('cell1',this.value)">
</form>
</body>
</html>

It works great, but is there any way to put something other than "tom" (the buttons exact value) in the cell? Say I wanted to put "tom smith" in the cell, but keep the button label as just "tom"

FJbrian
07-15-2002, 11:35 PM
sounds like the longest route possible to do something
why not just document.write?
or since it's a button, change the value of the button?
document.formname.buttonname.value=whatever

marie180
07-16-2002, 12:07 AM
LOL. Because I have really no idea what im doing - just trying to patch together other peoples scripts to suit my purpose :)

Heres what im trying to achieve:

Trying to make a tab menu that I can drop into the rest of my pages with an ssi file include.

The tabs menu is a table-
each tab consists of three cells
1. rounded corner gif
2. Text label (hyperlink or button - still deciding)
3. rounded corner gif

onMouseover the entire tab turns gray, onClick and it turns white (and stays that way) showing the user where they are on the site.

The content will be displayed in another cell lower on the page - of course each tab links to a different section on the site.

I can get the tabs to do the color change thing perfectly without links, but the thing 'resets' when a new page is loaded - thus loosing the white "this is where you are" tab.

I know this can be done easily wth an iFrame, but since that property isnt well supported (and i hate frames on principle) i am trying to do it with javascript and tables :)

In case anyone cares to look, heres the hack-job ive put together so far - perhaps there is a better way?
http://members.aol.com/marie180/personal/mymess.htm