Can this be done in JavaScript ?

P

pentium77

Basically I have a situation where I need to update changes occuring
in one Text field of a table into another text field located in
another table. In addition both the tables are located in different
frames of a HTML page. So my question is can such an update be done ?
Is it necessary that the tables be located in the same frame for the
update to work ? Any pointers would be appreciated ?

Thanks,
-P.
 
K

kaeli

Basically I have a situation where I need to update changes occuring
in one Text field of a table into another text field located in
another table. In addition both the tables are located in different
frames of a HTML page. So my question is can such an update be done ?
Is it necessary that the tables be located in the same frame for the
update to work ? Any pointers would be appreciated ?

Thanks,
-P.

It can be done IF:
All browsers using it are DOM compliant.
All browsers using it have javascript enabled.
All relevant frames come from the same domain and use the same protocol (http
or https, but both the same).

--
 
P

pentium77

Thanks Kaeli.

-P.

kaeli said:
It can be done IF:
All browsers using it are DOM compliant.
All browsers using it have javascript enabled.
All relevant frames come from the same domain and use the same protocol (http
or https, but both the same).

--
 
R

Robert

Basically I have a situation where I need to update changes occuring
in one Text field of a table into another text field located in
another table.

How does the text field change in the first table?

If you are already changing text in the first frame, all you have to
do is find the node in the table in the second frame and you can use
the same code to change the text in the second frame.
In addition both the tables are located in different
frames of a HTML page.
So my question is can such an update be done ?

I'll change some text in a table in another frame.

The tag id needs to be unique. Make certain that you do not have name
conflicts in IE.

With MacOS 10.2.6, I tested these in IE 5.2, Safari 1.0, and Netscape
7.2.

Robert


frames.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Frames Layout</title>
</head>
<frameset rows="45%,55%" >
<frame src="frame1.html"
id="myframe1"
name="nameframe1"
scrolling=yes>
<frame src="frame2.html"
id="myframe2"
name="nameframe2"
scrolling=yes>
</frameset>
</html>

frame1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>insert some text</title>
</head>
<body>
<p>Insert or change some text.
<br>
Don't forget to see what happens when you
press the button more than once.</p>
<form name="myForm">
<input type="text" name="total" size="20">
<br><br>
<input type="button"
name="activate"
value="change the text"
onclick="top.frames['nameframe2'].changeText('insert',
document.forms['myForm'].elements['total']);">
<br>
</form>
</body>
</html>

frame2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>frame 2</title>

<script type="text/javascript">
function changeText(spanId,text)
{
var node;
/* Find the span node. */
if (document.getElementById)
{
node = document.getElementById(spanId);
}
else if (document.all)
{
node = document.all[spanId];
}
else
{
alert("Constructs document.getElementByID " +
"and document.all are not available in this browser. " +
"You need to use a newer browser.");
return;
}

if (!node)
{
alert("You need to create a span tag with " +
"the id of " + spanId + ".");
return;
}

/* Insert the text. */

if (typeof node.innerHTML == "string")
{
/* Make innerHTML act like the simple text insert. */
node.innerHTML = text.value.replace(
/&/g, "&amp;").replace(
/</g, "&lt;").replace(
/>/g, "&gt;").replace(
/ /g, "&nbsp;");
}
else if (node.appendChild &&
document.createTextNode)
{
/* Since this is plan text, prevent multiple
blanks from being compressed into one. */
var theData = text.value.replace(/ /g, "\xA0");

/* If a node already exists, assume we
created it on a prior click by the user. */
var nextNode = node.firstChild;
if(nextNode)
{
/* Yes, replace the text. */
nextNode.data = theData;
}
else
{
/* No, Insert the new node. */
node.appendChild(
document.createTextNode(theData));
}
}
else
{
alert("Functions to insert text are not available. " +
"You need to use a newer browser.");
return;
}
}

</script>
</head>
<body>
<p>Text in this frame will be changed from frame 1.</p>
<table border="2">
<tr>
<td>
<p>Text in the cell below will be changed.</p>
</td>
</tr>
<tr>
<td>
<p>Change this "<span id='insert'></span>".</p>
</td>
</tr>
</table>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top