C
charles-brewster
I have progressed the copytext function test page a little since my
original post here in the small hours this morning. It now opens a
debugging window so I can try to figure out what it is or isn't doing.
Current version of the test page:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<head>
<title>Testing JavaScript</title>
<script language="JavaScript">
var _console = null;
function debug(msg)
{
if ((_console == null) || (_console.closed))
{
_console =
window.open("","console","width=600,height=300,resizable,screenX=50,screenY=50");
_console.document.open();
}
_console.focus();
_console.document.writeln(msg);
}
</script>
<script language="JavaScript">
function copytext(source_id, dest_id)
{
debug('source_id is ' + source_id + '<br>');
debug('dest_id is ' + dest_id + '<br>');
var s = document.getElementById(source_id);
var d = document.getElementById(dest_id);
var the_text = s.innerHTML;
debug('the_text is [' + the_text + ']<br>');
d.value = the_text;
// d.value = "some string data"
}
</script>
</head>
<body>
<h1>Testing JavaScript</h1>
<form>
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td id="cell1">
a string of text
</td>
<td>
<button onclick="copytext('cell1', 'input1');">>></button>
</td>
<td>
<input type="text" id="input1" width="20">
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="button" value="test debug" onclick="debug('Testing
debug(msg)<br>');">
</td>
</tr>
</table>
</form>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When passing a string literal to the <input>'s value attribute
(commented out in the script above) I do see the text flash in the
input text box on the screen momentarily, then disappear. When passing
the JavaScript variable containing the text I actually want to go in
there, nothing (at least in Netscape 7).
I tried replacing the function as it is above with
~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script language="JavaScript">
function copytext(source, dest)
{
var new_input = document.createElement("input");
var parent = dest.parentNode;
var the_text = source.innerHTML;
debug('the_text is [' + the_text + ']<br>');
var the_type = dest.getAttribute("type");
debug('the_type is [' + the_type + ']<br>');
var the_id = dest.getAttribute("id");
debug('the_id is [' + the_id + ']<br>');
var the_width = dest.getAttribute("width");
debug('the_width is [' + the_width + ']<br>');
new_input.setAttribute("type", the_type);
new_input.setAttribute("id", the_id);
new_input.setAttribute("width", the_width);
new_input.setAttribute("value", the_text);
debug('new_input is [' + new_input + ']<br>');
parent.replaceChild(new_input, dest);
}
</script>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and calling with
<button
onclick="copytext(document.getElementById('cell1'),
document.getElementById('input1'));"></button>
The debug window again shows the values being picked up OK in the
function, but no change happening at all on the page.
Any helpful suggestions would be most welcome
Many thnaks
CB
Any helpful suggestions or pointers would be much appreciates
original post here in the small hours this morning. It now opens a
debugging window so I can try to figure out what it is or isn't doing.
Current version of the test page:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<head>
<title>Testing JavaScript</title>
<script language="JavaScript">
var _console = null;
function debug(msg)
{
if ((_console == null) || (_console.closed))
{
_console =
window.open("","console","width=600,height=300,resizable,screenX=50,screenY=50");
_console.document.open();
}
_console.focus();
_console.document.writeln(msg);
}
</script>
<script language="JavaScript">
function copytext(source_id, dest_id)
{
debug('source_id is ' + source_id + '<br>');
debug('dest_id is ' + dest_id + '<br>');
var s = document.getElementById(source_id);
var d = document.getElementById(dest_id);
var the_text = s.innerHTML;
debug('the_text is [' + the_text + ']<br>');
d.value = the_text;
// d.value = "some string data"
}
</script>
</head>
<body>
<h1>Testing JavaScript</h1>
<form>
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td id="cell1">
a string of text
</td>
<td>
<button onclick="copytext('cell1', 'input1');">>></button>
</td>
<td>
<input type="text" id="input1" width="20">
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="button" value="test debug" onclick="debug('Testing
debug(msg)<br>');">
</td>
</tr>
</table>
</form>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When passing a string literal to the <input>'s value attribute
(commented out in the script above) I do see the text flash in the
input text box on the screen momentarily, then disappear. When passing
the JavaScript variable containing the text I actually want to go in
there, nothing (at least in Netscape 7).
I tried replacing the function as it is above with
~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script language="JavaScript">
function copytext(source, dest)
{
var new_input = document.createElement("input");
var parent = dest.parentNode;
var the_text = source.innerHTML;
debug('the_text is [' + the_text + ']<br>');
var the_type = dest.getAttribute("type");
debug('the_type is [' + the_type + ']<br>');
var the_id = dest.getAttribute("id");
debug('the_id is [' + the_id + ']<br>');
var the_width = dest.getAttribute("width");
debug('the_width is [' + the_width + ']<br>');
new_input.setAttribute("type", the_type);
new_input.setAttribute("id", the_id);
new_input.setAttribute("width", the_width);
new_input.setAttribute("value", the_text);
debug('new_input is [' + new_input + ']<br>');
parent.replaceChild(new_input, dest);
}
</script>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and calling with
<button
onclick="copytext(document.getElementById('cell1'),
document.getElementById('input1'));"></button>
The debug window again shows the values being picked up OK in the
function, but no change happening at all on the page.
Any helpful suggestions would be most welcome
Many thnaks
CB
Any helpful suggestions or pointers would be much appreciates