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

How to set text in a cell

My web page has thumbnail pictures, and when the user clicks on a
thumbnail, I change the image source of a full-size image elsewhere on
the page. I'd also like to change the caption of the full-size image,
but I'm not sure how to set the value of the text. I've tried creating
a form with a single input field, and I can set the value of that
field, but the field has a sunken style that I can't get rid of, and
I'd like to find a different way of displaying the text.

Is there an easier way to change the value of a text field?

Thanks,

Tom

Jul 23 '05 #1
4 1723
On Wed, 09 Mar 2005 14:31:04 -0800, ziggy.696040 wrote:
My web page has thumbnail pictures, and when the user clicks on a
thumbnail, I change the image source of a full-size image elsewhere on
the page. I'd also like to change the caption of the full-size image,
but I'm not sure how to set the value of the text. I've tried creating
a form with a single input field, and I can set the value of that
field, but the field has a sunken style that I can't get rid of, and
I'd like to find a different way of displaying the text.

Is there an easier way to change the value of a text field?

Thanks,

Tom


You don't need a form. Use an anchor and the innerHTML function.

<a name='myanchor'></a>

document.myanchor.innerHTML = '<b>my file name</b>';

Will change the page to:

<a name='myanchor'><b>my file name</b></a>

--
Life is short, but wide. -KV

Jul 23 '05 #2
Ivan Marsh wrote:
On Wed, 09 Mar 2005 14:31:04 -0800, ziggy.696040 wrote:

My web page has thumbnail pictures, and when the user clicks on a
thumbnail, I change the image source of a full-size image elsewhere on
the page. I'd also like to change the caption of the full-size image,
but I'm not sure how to set the value of the text. I've tried creating
a form with a single input field, and I can set the value of that
field, but the field has a sunken style that I can't get rid of, and
I'd like to find a different way of displaying the text.

Is there an easier way to change the value of a text field?

Thanks,

Tom

You don't need a form. Use an anchor and the innerHTML function.


The OP is better off to use a <span> rather than an <a> tag.

<a> is intended for navigation, either as a destination
(anchor) or link, whereas <span> is for in-line markup and does
not infer any presentational idiom or display characteristics
and therefore seems to better suit the OP's need.

<a name='myanchor'></a>

document.myanchor.innerHTML = '<b>my file name</b>';

Will change the page to:

<a name='myanchor'><b>my file name</b></a>


Not in any browser I tested. Removing "document." provides an
IE specific way of referencing a named element that will not
work in most other browsers.

A better, cross browser, standards compliant method is to add a
span in the HTML where the text is to appear, then modify its
content:

<span id="caption_00">the caption will appear here</span>

Then on the thumbnail onclick, add the script to change it:

<img ... onclick="changeCaption('caption_00',
'Here is the new caption');" ...>

And somewhere in the page (preferably in the head), put the
script that modifies the caption:

<script type="text/javascript">
function changeCaption(ele,txt) {
if (document.getElementById) {
document.getElementById(ele).firstChild.data = txt;
} else if (document.all) {
document.all[ele].firstChild.data = txt;
}
}
</script>

The function could be made more generic by having it use the
alt tag of the image for the caption and if its id is related to
the image to the id of the span, then the onclick could be
attached dynamically so that there is no need to add code for
the onclick to every thumbnail.

Always remembering of course that users without JavaScript
support will not see anything happen when the thumbnail is
clicked.
--
Rob
Jul 23 '05 #3
RobG wrote:
[...]
A better, cross browser, standards compliant method is to add a
span in the HTML where the text is to appear, then modify its
content:

<span id="caption_00">the caption will appear here</span>
Should mention that the suggested method only works if there
something in the <span> already, that is, that it has a
firstChild. If the span is intended to be empty, then use a
non-breaking space as the default:

<span id="caption_00">&nsbp;</span>

or modify the non-standard-but-widely-supported innerHTML
attribute of the span:

[...] function changeCaption(ele,txt) {
if (document.getElementById) {
document.getElementById(ele).firstChild.data = txt;
} else if (document.all) {
document.all[ele].firstChild.data = txt;
}


function changeCaption(ele,txt) {
if (document.getElementById) {
document.getElementById(ele).innerHTML = txt;
} else if (document.all) {
document.all[ele].innerHTML = txt;
}

[...]

--
Rob
Jul 23 '05 #4
DU
RobG wrote:
RobG wrote:
[...]
A better, cross browser, standards compliant method is to add a
span in the HTML where the text is to appear, then modify its
content:

<span id="caption_00">the caption will appear here</span>

Should mention that the suggested method only works if there
something in the <span> already, that is, that it has a
firstChild.


Since the function targets only a specific node under controlled
circumstances (design requirements are clear and limited), then it is
safe to ignore this issue. If you want to use a more generic, more
general function for setting text of a node (or subtree) - and I do not
recommend doing so here -, then you need to create a function meeting
such design requirements.

If the span is intended to be empty, then use a non-breaking space as the default:

<span id="caption_00">&nsbp;</span>

or modify the non-standard-but-widely-supported innerHTML
attribute of the span:

[...]
function changeCaption(ele,txt) {
if (document.getElementById) {
document.getElementById(ele).firstChild.data = txt;
} else if (document.all) {
document.all[ele].firstChild.data = txt;
}

function changeCaption(ele,txt) {
if (document.getElementById) {
document.getElementById(ele).innerHTML = txt;

All of the browsers which support getElementById also support nodeType
attribute, nodeName attribute, firstChild, childNodes[], nodeValue and
data attributes so there is no need to resort to innerHTML here. Very
very few browsers still in use today on the web do not support
firstChild.data (or childNodes[0].nodeValue) and, in which case - eg
MSIE 4 -, innerText will be much faster, efficient.
} else if (document.all) {
document.all[ele].innerHTML = txt;
}

[...]


DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.6 :)
Jul 23 '05 #5

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

Similar topics

1
by: johkar | last post by:
I have a grid. When the focus is put on a cell an input is created with the value being the cell's text. I would like to size the input to the physical width of the text. Ideas? John ...
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
3
by: Bill M. | last post by:
Hello, What's up with this? I've got a <td id="container"> and want to set the text in this cell like .... var container = document.getElementById('container'); container.data = "Data in...
3
by: Peter | last post by:
Hello, Thanks for reviewing my quesiton. What does a website need in order to send text messaging to cell phones? Is this something the hosting company will offer or does the website need...
7
by: Marios Koumides | last post by:
I post the same question few days ago but there was a confusion in the answers. Anywayz I am posting again. I have a form with 96 textboxes (8 rows x 12 columns) Now I want in the last row to have...
1
by: john | last post by:
I want to set the cell width and height such that the cell doesn't get bigger. If the text is too long for the cell, it should be clipped. It only has to work for IE. I have tried setting the...
5
by: DONE1 | last post by:
Hello There, I am trying to write a macro that will copy part of Text in a Cell & then paste in another cell. For example, assume cell A1="ABE_BC1 AbTS 11 bisTSport 2", I would like to copy/Paste...
1
by: meworkingman | last post by:
I'm a relative CSS newbie and I'm trying to do the following: I have a table that holds text that might span multiple cells. I want it to look something like this: ...
1
by: DaveyP | last post by:
I have a user control (called data_dictionary) which I need to add into the header text of a datagrid. I'm doing this by adding the control in the RowCreated event as follows: dds_descriptions...
1
by: swetha123 | last post by:
hello , I need to alert the value entered in the text box,which is in TD cell, using DOM can any one tell how please here is the code with out a text box which is working <html> <head> ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.