Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Still trying to copy table cell text into an input as value attribute (http://www.velocityreviews.com/forums/t925441-still-trying-to-copy-table-cell-text-into-an-input-as-value-attribute.html)

charles-brewster@ntlworld.com 06-22-2006 11:21 AM

Still trying to copy table cell text into an input as value attribute
 
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,res izable,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


RobG 06-22-2006 12:00 PM

Re: Still trying to copy table cell text into an input as value attribute
 
charles-brewster@ntlworld.com wrote:
> 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.


[...]

See my reply to your first post.

Regarding a function for getting the textContent/innerText of an
element, try here:

<URL:http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/9c8d5b2796cc437f/6366e98e3a71cdf7?q=innerText+textContent+robg&rnum =1#6366e98e3a71cdf7>


--
Rob

charles-brewster@ntlworld.com 06-22-2006 01:22 PM

Re: Still trying to copy table cell text into an input as value attribute
 
RobG wrote:
> See my reply to your first post.
>


Seen - and very many thanks to you

> Regarding a function for getting the textContent/innerText of an
> element, try here:
>
> <URL:http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/9c8d5b2796cc437f/6366e98e3a71cdf7?q=innerText+textContent+robg&rnum =1#6366e98e3a71cdf7>


That worked fine, and changing to <input type="button" ....> causes the
value to stay where it's put after clicking.

For your interest the page I'm hoping to use this on is here:
http://www.iearneurope.org/lingo/index.php
It should save users a bit of typing.

If you'd like a mention on the 'acknowledgements' page on the site I'm
happy to oblige.

Next JavaScript job on there will be a translation popup window with
(hopefully) click-and-drag to allow a user to rearrange word-order in a
type="text" <input> before sending a different language rendition of
some english text into a database.

I daresay you'll see me back here once I get started on that!

With many thanks for your help

CB



All times are GMT. The time now is 07:24 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.