473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

inserting text on table cell from external js

Ben
Hi all,

I'm trying to write inside a table cell from external javascript but
am not successful. When I insert inside a form within <td...>, it
works but does not work for normal table cell. My codes are as
follows; please read comments on the code:

index.html
----------
<html>
<head>
<title>Hello World</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<link href="styles.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript"
src="jatest.js"></script>
</head>

<body onLoad="startclock()">
<center>

<table width="100%" height="431" border="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="148" height="23">&nbsp;</td>
<td width="346">&nbsp;</td>
<td id="date" width="104" valign="top"><div align="right">
/************************************************** ***/
/*** I WANT TO CALL date() FR0M EXTERNAL FILE HERE ***/
/*********************** HOW??? **********************/
/************************************************** ***/
</div></td>
<td width="148"> <div align="right"> </div></td>
<tr>
<td width="148" height="40">&nbsp;</td>
<td>&nbsp;</td>
<td valign="top"> <div align="right">
<form name="clock">
<input align="right" border="0" type="text" name="face"
size=13 readonly="true">
</form>
</div></td>
<td width="148"> <div align="right"></div></td>
</tr>
</table>

</center>
</body>
</html>
jatest.js
----------
var timerID = null;
var timerRunning = false;

function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}

function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"
document.clock.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}

function startclock() {
stopclock();
showtime();
}

function date() {
var mydate=new Date()
var day=mydate.getDay()
var mydate=new Date()
var year=mydate.getFullYear()
var month=mydate.getMonth()
var daym=mydate.getDate()
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thu rsday",
"Friday","Saturday")
var montharray=new Array("January","February","March","April","May"," June"
,"July","August","September","October","November", "December")
document.date.write(dayarray[day]+", ")
document.date.write(montharray[month]+" "+daym+", "+year)&nbsp
}

Hope some of you can help me...

Thanx
Ben
Jul 23 '05 #1
1 2434
"Ben" <cr*********@yahoo.com> skrev i meddelandet
news:d9**************************@posting.google.c om...
Hi all,

I'm trying to write inside a table cell from external javascript but
am not successful. When I insert inside a form within <td...>, it
works but does not work for normal table cell. My codes are as
follows; please read comments on the code:

<code snipped>

You'll want to look up DOM (and its limitations browser-wise).

I'm a DOM newbie myself, so this code is probably suboptimal, but the
following works in IE 6 and Netscape 7 for Windows:

<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function setCellText(inText){

var theTable = document.getElementById("thing");
var theRows = null;
var theColumns = null;

if(theTable){

theRows = theTable.getElementsByTagName("tr");

if(theRows.length > 0){

// Access columns of first row
theColumns = theRows[0].getElementsByTagName("td");

if(theColumns.length > 0){

// Add a text node to the first column
theColumns[0].appendChild(document.createTextNode(inText));

}
}
}
}
</script>

</head>

<body>
<table id="thing">
<tr><td></td><td></td></tr>
</table>

<form name="form1" >
<input type="button" name="test" value="Try it out"
onclick="setCellText('yadda yadda');">
</form>
</body>
</html>

Joakim Braun
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Asad | last post by:
I have a form on a page that has several textareas, and textboxes inside a table (so the table containing the textboxes is also inside the FORM tag). I want to replace the textareas with simple...
1
by: MQ | last post by:
I have been trying to insert a col tag using DOM but I can't seem to make it work. In the following script I create a table with rows and columsn. I tried to modify the column style, but doesn't...
7
by: Andrew Poulos | last post by:
I'm using the following code to create a small table with one column and two rows. An image goes into the first cell. //create table var t = document.createElement("TABLE"); t.style.position =...
4
by: Tom Dauria | last post by:
What I am trying to do is write a resume into a word document from information in an Access database. I have been using bookmarks and inserting table results into the document and so far it's...
2
by: Ceri | last post by:
I am running an ASP.Net project that runs 30 lengthy SQL Stored Procedures (each takes around 20 seconds to complete). As each Stored Procedure completes, I want to indicate in a table cell that it...
8
by: Stefan Mueller | last post by:
I'm really very confused. With the following code I can add rows/fields in frame 1 and 2. If I use IE, Mozilla or Opera the new rows/fields get added in ascending order. However, if I use Safari...
11
by: Mellow Crow | last post by:
I had a problem in IE 6 when trying to insert a table using W3C DOM techniques. I found a solution and share it. :) Initially I had...... ********************** <!DOCTYPE html PUBLIC...
2
by: Serious_Practitioner | last post by:
Hi, and thank you in advance for any assistance. I would like to use a script to determine if a date meets a condition, and, if it does, then create a table row with a couple of cells, and then...
1
by: jamesm6162 | last post by:
Hi I have the following XSL-FO document that I'm testing with the FOP processor. The table I put in, however, is completely stuck to the left side of the body-region, regardless of which margins...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.