473,386 Members | 1,758 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,386 software developers and data experts.

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

Jun 22 '06 #1
2 1851
ch**************@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
Jun 22 '06 #2
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

Jun 22 '06 #3

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

Similar topics

25
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
1
by: cotton_gear | last post by:
Hello, Fiest of all let me thank this group for so quick in responding to any postings. I am using a javascript based utility from a site to sort the columns of the table. But, for some strange...
1
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
6
by: anirban.anirbanju | last post by:
hi there, i've some serious problem to add rows dynamically in a table. my table contains 5 cell. | check | from_value | to_value | color_text | color_value |...
2
by: philin007 | last post by:
Hi Guys, Could any one help me out with codes to add rows to a table. Well I kinda of got the codes from the following site (http://www.interviewboard.com/DHTMLSamples/DHTMLGridSample.htm) the...
1
by: planetthoughtful | last post by:
Hi All, I have a web page that presents records in a table, with one row per record. I'd like to put an edit button next to each record, such that if a user clicks on the edit button next to...
4
by: prosad | last post by:
hello, Just solved a problem using Javascript onclick, can click on any cell in a dynamic table and it will pass the innerText object value to my form text field. parts of code given below: ...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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.