473,507 Members | 6,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing Text

I'm trying to text the text inside id="DirectorsCaption" within the
hideDirectors() and showDirectors() functions but it's not working. I'm
trying different variations using .innerHTML but with no luck so far.
Thanks.

<tr>
<td id="DirectorsCaption">ALL CURRENT AND RETIRED
DIRECTORS</td>
</tr>

<tr>
<td>
<input type="button" value="Current directors only"
onclick="hideDirectors();" />
<input type="button" value="All current and retired directors"
onclick="showDirectors();" />
</td>
</tr>
function hideDirectors( ) {
displayDirectors(false);
// document.getElementById("DirectorsCaption").innerH TML = "CURRENT
DIRECTORS";
document.all[DirectorsCaption].innerHTML = "CURRENT DIRECTORS";
}

function showDirectors( ) {
displayDirectors(true);
// document.getElementById("DirectorsCaption").innerH TML = "ALL
CURRENT AND RETIRED DIRECTORS";
document.all[DirectorsCaption].innerHTML = "ALL CURRENT AND RETIRED
DIRECTORS";
}

Mar 10 '06 #1
10 1666
ev*******@gmail.com wrote on 10 mrt 2006 in comp.lang.javascript:
I'm trying to text the text inside id="DirectorsCaption" within the
hideDirectors() and showDirectors() functions but it's not working. I'm
trying different variations using .innerHTML but with no luck so far.
Thanks.

<tr>
<td id="DirectorsCaption">ALL CURRENT AND RETIRED
DIRECTORS</td>
</tr>

<tr>
<td>
<input type="button" value="Current directors only"
onclick="hideDirectors();" />
<input type="button" value="All current and retired directors"
onclick="showDirectors();" />
Why use buttons that are not doing anything? Only one is usefull at a
time!

</td>
</tr>
function hideDirectors( ) {
displayDirectors(false);
// document.getElementById("DirectorsCaption").innerH TML = "CURRENT
DIRECTORS";
Choose for the more general: getElementById()

document.all[DirectorsCaption].innerHTML = "CURRENT DIRECTORS";
Use css when needing only a specific hyding.
}

function showDirectors( ) {
displayDirectors(true);
// document.getElementById("DirectorsCaption").innerH TML = "ALL
CURRENT AND RETIRED DIRECTORS";
document.all[DirectorsCaption].innerHTML = "ALL CURRENT AND RETIRED
DIRECTORS";
}


Try:

<tr><td>
ALL CURRENT
<span id='Retired'>AND RETIRED</span>
DIRECTORS
</td></tr>

<tr><td>
<input type='button'
value='Current directors only'
onclick='toggleRetired(this);'>
</td></tr>

...............

var Retired = document.getElementById('Retired')

function toggleRetired(x) {
if (x.value=='Current directors only'){
Retired.style.display = 'none';
x.value = 'Retired directors too';
} else {
Retired.style.display = '';
x.value = 'Current directors only';
}
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 10 '06 #2
Evertjan. said the following on 3/10/2006 3:12 PM:

<snip>
var Retired = document.getElementById('Retired')

function toggleRetired(x) {
var Retired = document.getElementById('Retired');
if (x.value=='Current directors only'){
Retired.style.display = 'none';
x.value = 'Retired directors too';
} else {
Retired.style.display = '';
x.value = 'Current directors only';
}
}


Firefox: Retired has no properties.
IE6: Line 12 Char 9 Object Expected.

Moving the Retired var declaration to inside the function removes the
errors. You can't set Retired equal to a reference to an element that
doesn't exist yet. Unless the script block is after the table. Move the
declaration, lose the Global variable, put the script block in the head
section with all the rest of the script blocks :)
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 10 '06 #3
Thanks. I agree the one button approach is better but why isn't my code
working? Seems like this should work.

<tr>
<td>span id="DirectorsCaption">ALL CURRENT AND RETIRED
DIRECTORS</span></td>
</tr>

function hideDirectors( ) {
displayDirectors(false);
document.getElementById("DirectorsCaption").innerH TML = "CURRENT
DIRECTORS";
}

function showDirectors( ) {
displayDirectors(true);
document.getElementById("DirectorsCaption").innerH TML = "ALL CURRENT
AND RETIRED DIRECTORS";
}

Mar 10 '06 #4
Randy Webb wrote on 10 mrt 2006 in comp.lang.javascript:
Evertjan. said the following on 3/10/2006 3:12 PM:

<snip>


Not only snipped, you changed the position of my code!
var Retired = document.getElementById('Retired')

function toggleRetired(x) {


var Retired = document.getElementById('Retired');
if (x.value=='Current directors only'){
Retired.style.display = 'none';
x.value = 'Retired directors too';
} else {
Retired.style.display = '';
x.value = 'Current directors only';
}
}


Firefox: Retired has no properties.
IE6: Line 12 Char 9 Object Expected.

Moving the Retired var declaration to inside the function removes the
errors. You can't set Retired equal to a reference to an element that
doesn't exist yet. Unless the script block is after the table. Move the
declaration, lose the Global variable, put the script block in the head
section with all the rest of the script blocks :)


The

var Retired = document.getElementById('Retired')

was set BELOW the html elemnet, If you wnat it in the <head>,
you would have te run it in an <body onload function.

Setting the above inside the function is entirly possible, but not
educational, as repeatedly assichning the same should be discouraged.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 10 '06 #5
ev*******@gmail.com wrote:
Thanks. I agree the one button approach is better but why isn't my code
working? Seems like this should work.

<tr>
<td>span id="DirectorsCaption">ALL CURRENT AND RETIRED ^[1] DIRECTORS</span></td>
</tr>

function hideDirectors( ) {
displayDirectors(false); ^^^^^^^^^^^^^^^^^^^^^^^^[2] document.getElementById("DirectorsCaption").innerH TML = "CURRENT [3]^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^[4]^^^^^^^^^[5] ^^^^^^^[6] DIRECTORS";
}

function showDirectors( ) {
displayDirectors(true);
document.getElementById("DirectorsCaption").innerH TML = "ALL CURRENT
AND RETIRED DIRECTORS";
}


There can be a number of reasons.

[^1] There is no `span' element, the start tag is missing.
[^2] Something goes wrong in displayDirectors().
[^3] document.getElementById() is not supported.

[^4] document.getElementById() does not return an object reference.
See also [1], and
<URL:http://www.jibbering.com/faq/faq_notes/not_browser_detect.html#bdFD>

[^5] `innerHTML' is not supported.
[^6] Your code is word-wrapped because it exceeds column 80 (or less),
hence there is a syntax error ("unterminated string literal").

<URL:http://jibbering.com/faq/#FAQ4_43>

BTW: Do not uppercase the text, let CSS do this for you
(text-transform:uppercase). And ISTM a `span' element is
not appropriate here either, this looks like a heading.
PointedEars
Mar 11 '06 #6
Thomas 'PointedEars' Lahn said the following on 3/11/2006 5:28 PM:
ev*******@gmail.com wrote:
Thanks. I agree the one button approach is better but why isn't my code
working? Seems like this should work.

<tr>
<td>span id="DirectorsCaption">ALL CURRENT AND RETIRED ^[1]
DIRECTORS</span></td>
</tr>

function hideDirectors( ) {
displayDirectors(false);

^^^^^^^^^^^^^^^^^^^^^^^^[2]
document.getElementById("DirectorsCaption").innerH TML = "CURRENT

[3]^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^[4]^^^^^^^^^[5] ^^^^^^^[6]
DIRECTORS";
}

function showDirectors( ) {
displayDirectors(true);
document.getElementById("DirectorsCaption").innerH TML = "ALL CURRENT
AND RETIRED DIRECTORS";
}


There can be a number of reasons.

[^1] There is no `span' element, the start tag is missing.
[^2] Something goes wrong in displayDirectors().
[^3] document.getElementById() is not supported.

[^4] document.getElementById() does not return an object reference.
See also [1], and
<URL:http://www.jibbering.com/faq/faq_notes/not_browser_detect.html#bdFD>

[^5] `innerHTML' is not supported.
[^6] Your code is word-wrapped because it exceeds column 80 (or less),
hence there is a syntax error ("unterminated string literal").


7) None of the above.
8) The over use of footnotes.
<URL:http://jibbering.com/faq/#FAQ4_43>

BTW: Do not uppercase the text, let CSS do this for you
(text-transform:uppercase).


Nonsense.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 12 '06 #7
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 3/11/2006 5:28 PM:
BTW: Do not uppercase the text, let CSS do this for you
(text-transform:uppercase).


Nonsense.


Not everything you do not comprehend is nonsense. Of course
I did not mean not to use any uppercase character.
PointedEars
Mar 12 '06 #8
Thomas 'PointedEars' Lahn said the following on 3/11/2006 7:53 PM:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 3/11/2006 5:28 PM:
BTW: Do not uppercase the text, let CSS do this for you
(text-transform:uppercase). Nonsense.


Not everything you do not comprehend is nonsense.


You fail to understand that I *do* comprehend it. Very well in fact.
Of course I did not mean not to use any uppercase character.


The nonsense is letting CSS control it. What if CSS is not supported,
disabled, or doesn't support text-transform-uppercase?

CSS is a suggestion and if that suggestion is not followed? The best
course of action with letters and case is to simply type it the way you
want it to appear. Then, it will *always* appear that way.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 12 '06 #9
On 12/03/2006 05:59, Randy Webb wrote:

[Using CSS to present text in upper case]
The nonsense is letting CSS control it. What if CSS is not supported,
disabled, or doesn't support text-transform-uppercase?
If case is purely presentational, as it was in the OP, then who cares if
CSS is disabled? The text will be shown in title case.

The content is "Current Directors". The desired presentation is "CURRENT
DIRECTORS". It really shouldn't matter which is the rendered result,
especially if that result is consistent.

Clearly, if the /content/ is upper-case ('HTML', for example) then CSS
shouldn't be used in that case.
CSS is a suggestion and if that suggestion is not followed?


The document will render perfectly fine, and it will be just as readable
(arguably more so, in this instance).

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Mar 12 '06 #10
Michael Winter said the following on 3/12/2006 7:31 AM:
On 12/03/2006 05:59, Randy Webb wrote:

[Using CSS to present text in upper case]
The nonsense is letting CSS control it. What if CSS is not supported,
disabled, or doesn't support text-transform-uppercase?
If case is purely presentational, as it was in the OP, then who cares if
CSS is disabled? The text will be shown in title case.


That's not what Thomas suggested. Thomas suggested something like this:

<span style="text-transform: uppercase">current directors</span>

<span style="text-transform: uppercase">if i want this text uppercased
then it matters</span>

THE ONLY WAY THIS TEXT WONT BE UPPERCASED IS IF THE USER HAS A
STYLESHEET THAT LOWERCASES IT.

User has browser set to ignore all styles in a webpage (IE).
My text appears the way I want it. The CSS transformed text doesn't.

User has a browser that doesn't support text-transform: uppercase.
My text appears the way I want it. The CSS transformed text doesn't.

That list goes on and on. The only one where my text will be altered is
if the user has a stylesheet to set all case to a particular way and
then it won't matter because both of our text will get transformed.

Result? Type it the way you want it, then it appears the way you want it.

That makes using CSS to transform case a nonsense approach other than to
be able to say "I added some extra code to do what I could have done
myself".
The content is "Current Directors". The desired presentation is "CURRENT
DIRECTORS". It really shouldn't matter which is the rendered result,
especially if that result is consistent.
Clearly, if the /content/ is upper-case ('HTML', for example) then CSS
shouldn't be used in that case.


That is precisely what the OP was doing. It was all uppercase, Thomas
said don't do that - use CSS to do it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Mar 13 '06 #11

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

Similar topics

3
6627
by: Cengiz Ulku | last post by:
Hi all, I know now how to change the font name of a RTF file in a RTB control using, for example: RTextBox1.SelFontName = cmbFonts.Text I have a RTF file -created with Word- displayed in a...
2
11013
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...
2
1541
by: pablo | last post by:
Dear NGers, I want to keep some images just left of some DIVs. But a change in text size leaves my images at the original position. Which event is generated by changing the text size from the...
5
1653
by: martin | last post by:
I needed a way to display calculated, multiple, changing values (numerical sums) as users interacted with the page, and do this without going back to the server to load the page again. What I...
7
6566
by: Frostillicus | last post by:
Hi, I've written some javascript to randomly choose a classical music composer's picture and sample audio and display it on my home page (http://marc.fearby.com/), and this works fine in Mozilla...
2
4267
by: John Smith | last post by:
Hey folks, I've got a combobox (DropDown List) in a windows form application which is bound to a DataSet. It's value is set to a numeric ID. It's visible text is set to a date. I need to make...
7
2929
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
2
1213
by: samonline | last post by:
Dear friends, I have written a little program to read the source of a web page into a Rich Text Box. Now I want to find a specific integer value in that text box and take it into a variable. That...
7
15015
by: sphinney | last post by:
I have a datasheet style form with textbox (MyTextBox) that has the Text Format property set to "Rich Text". It is bound to a memo field in a table. How do I change the text or highlight color of...
0
7221
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
7372
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...
1
7029
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
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
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,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.