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

inserting line breaks in text quoted in javascript

I'm doing some text swapping with javascript, got it working fine, but
I would like the line to have line breaks and being a beginner, I
don't even know if this is possible.
So I have a line like this
swaptext('Shaun, Greg, Violet, Joel, 1999')";
and I would like 1999 to be on a new line. Is there a simple way to do
this? I'd swear I've seen a way, but now I can't seem to find it.

Mar 17 '07 #1
20 16589
alice wrote:
I'm doing some text swapping with javascript, got it working fine, but
I would like the line to have line breaks and being a beginner, I
don't even know if this is possible.
So I have a line like this
swaptext('Shaun, Greg, Violet, Joel, 1999')";
and I would like 1999 to be on a new line. Is there a simple way to do
this? I'd swear I've seen a way, but now I can't seem to find it.
A new line where? In source code? In web page?
And what does the function "swaptext()" do?
So many qustions...
Mick
Mar 17 '07 #2
On Mar 17, 4:47 pm, Michael White <m...@mickweb.comwrote:
alice wrote:
I'm doing some text swapping with javascript, got it working fine, but
I would like the line to have line breaks and being a beginner, I
don't even know if this is possible.
So I have a line like this
swaptext('Shaun, Greg, Violet, Joel, 1999')";
and I would like 1999 to be on a new line. Is there a simple way to do
this? I'd swear I've seen a way, but now I can't seem to find it.

A new line where? In source code? In web page?
And what does the function "swaptext()" do?
So many qustions...
Mick
Sorry, I should have explained more. It's all part of an onclick
function
onClick="if (document.images) document.images['blank'].src = 'images/
new.gif'; swaptext('Shaun, Greg, Violet, Joel, 1999')";>
The functions for both the image swap and the text swap are in the
head of the html, and it's all working perfectly. I just want to know
if there is a way to insert a line break before '1999'. How do I do
that when it is already a quote within a javascript line? I can't just
add a <brbefore it.

Mar 18 '07 #3

alice wrote:
I'm doing some text swapping with javascript, got it working fine, but
I would like the line to have line breaks and being a beginner, I
don't even know if this is possible.
So I have a line like this
swaptext('Shaun, Greg, Violet, Joel, 1999')";
and I would like 1999 to be on a new line. Is there a simple way to do
this? I'd swear I've seen a way, but now I can't seem to find it.
swaptext('Shaun, Greg, Violet, Joel, \n1999')";

will work for text, for HTML -use:

swaptext('Shaun, Greg, Violet, Joel,<br1999')";

Mar 18 '07 #4
On Mar 17, 5:02 pm, scripts.cont...@gmail.com wrote:
alice wrote:
I'm doing some text swapping with javascript, got it working fine, but
I would like the line to have line breaks and being a beginner, I
don't even know if this is possible.
So I have a line like this
swaptext('Shaun, Greg, Violet, Joel, 1999')";
and I would like 1999 to be on a new line. Is there a simple way to do
this? I'd swear I've seen a way, but now I can't seem to find it.

swaptext('Shaun, Greg, Violet, Joel, \n1999')";

will work for text, for HTML -use:

swaptext('Shaun, Greg, Violet, Joel,<br1999')";
Neither of those is working.
the \n creates a space but no line break, and the <brshows up in the
text itself.

The header function is as follows
function swaptext(what)
{document.getElementById("text").firstChild.nodeVa lue=what;}

Then I have a div with the id="text".

Mar 18 '07 #5
alice wrote:
On Mar 17, 5:02 pm, scripts.cont...@gmail.com wrote:
>alice wrote:
>>I'm doing some text swapping with javascript, got it working fine, but
I would like the line to have line breaks and being a beginner, I
don't even know if this is possible.
So I have a line like this
swaptext('Shaun, Greg, Violet, Joel, 1999')";
and I would like 1999 to be on a new line. Is there a simple way to do
this? I'd swear I've seen a way, but now I can't seem to find it.
swaptext('Shaun, Greg, Violet, Joel, \n1999')";

will work for text, for HTML -use:

swaptext('Shaun, Greg, Violet, Joel,<br1999')";

Neither of those is working.
the \n creates a space but no line break, and the <brshows up in the
text itself.

The header function is as follows
function swaptext(what)
{document.getElementById("text").firstChild.nodeVa lue=what;}

Then I have a div with the id="text".
Use innerHTML instead of nodeValue, and use the <brversion.
Mar 18 '07 #6
On Mar 18, 12:21 am, TheBagbournes <n...@noway.comwrote:
alice wrote:
On Mar 17, 5:02 pm, scripts.cont...@gmail.com wrote:
alice wrote:
I'm doing some text swapping with javascript, got it working fine, but
I would like the line to have line breaks and being a beginner, I
don't even know if this is possible.
So I have a line like this
swaptext('Shaun, Greg, Violet, Joel, 1999')";
and I would like 1999 to be on a new line. Is there a simple way to do
this? I'd swear I've seen a way, but now I can't seem to find it.
swaptext('Shaun, Greg, Violet, Joel, \n1999')";
will work for text, for HTML -use:
swaptext('Shaun, Greg, Violet, Joel,<br1999')";
Neither of those is working.
the \n creates a space but no line break, and the <brshows up in the
text itself.
The header function is as follows
function swaptext(what)
{document.getElementById("text").firstChild.nodeVa lue=what;}
Then I have a div with the id="text".

Use innerHTML instead of nodeValue, and use the <brversion.- Hide quoted text -

- Show quoted text -
When I do that, the text does not swap out at all.

Mar 18 '07 #7
On Mar 18, 11:31 am, "alice" <a...@fearofdolls.comwrote:
On Mar 18, 12:21 am, TheBagbournes <n...@noway.comwrote:


alice wrote:
On Mar 17, 5:02 pm, scripts.cont...@gmail.com wrote:
>alice wrote:
>>I'm doing some text swapping with javascript, got it working fine, but
>>I would like the line to have line breaks and being a beginner, I
>>don't even know if this is possible.
>>So I have a line like this
>>swaptext('Shaun, Greg, Violet, Joel, 1999')";
>>and I would like 1999 to be on a new line. Is there a simple way to do
>>this? I'd swear I've seen a way, but now I can't seem to find it.
>swaptext('Shaun, Greg, Violet, Joel, \n1999')";
>will work for text, for HTML -use:
>swaptext('Shaun, Greg, Violet, Joel,<br1999')";
Neither of those is working.
the \n creates a space but no line break, and the <brshows up in the
text itself.
The header function is as follows
function swaptext(what)
{document.getElementById("text").firstChild.nodeVa lue=what;}
Then I have a div with the id="text".
Use innerHTML instead of nodeValue, and use the <brversion.- Hide quoted text -
- Show quoted text -

When I do that, the text does not swap out at all.- Hide quoted text -

- Show quoted text -
I'm getting the feeling it may have to do with the text that is being
replaced. What I have is
<div id="text">phototext
</div>
And the word phototext is swapped out with the names. Do I need to do
something else with this to allow it to be able to "use" the line
break? I've tried adding a <brand another line of text after
'phototext', but I'm wondering, do I need something else, like for it
to be in a table, a span, a blockquote, a paragraph, something else?
The \n (and I've treid \r as well) are trying to do something, it's as
if they just can't really make a new line becuase there isn't a place
for it, maybe?

Mar 18 '07 #8
alice wrote:
On Mar 18, 11:31 am, "alice" <a...@fearofdolls.comwrote:
>On Mar 18, 12:21 am, TheBagbournes <n...@noway.comwrote:


>>alice wrote:
On Mar 17, 5:02 pm, scripts.cont...@gmail.com wrote:
alice wrote:
>I'm doing some text swapping with javascript, got it working fine, but
>I would like the line to have line breaks and being a beginner, I
>don't even know if this is possible.
>So I have a line like this
>swaptext('Shaun, Greg, Violet, Joel, 1999')";
>and I would like 1999 to be on a new line. Is there a simple way to do
>this? I'd swear I've seen a way, but now I can't seem to find it.
swaptext('Shaun, Greg, Violet, Joel, \n1999')";
will work for text, for HTML -use:
swaptext('Shaun, Greg, Violet, Joel,<br1999')";
Neither of those is working.
the \n creates a space but no line break, and the <brshows up in the
text itself.
The header function is as follows
function swaptext(what)
{document.getElementById("text").firstChild.nod eValue=what;}
Then I have a div with the id="text".
Use innerHTML instead of nodeValue, and use the <brversion.- Hide quoted text -
- Show quoted text -
When I do that, the text does not swap out at all.- Hide quoted text -

- Show quoted text -

I'm getting the feeling it may have to do with the text that is being
replaced. What I have is
<div id="text">phototext
</div>
And the word phototext is swapped out with the names. Do I need to do
something else with this to allow it to be able to "use" the line
break? I've tried adding a <brand another line of text after
'phototext', but I'm wondering, do I need something else, like for it
to be in a table, a span, a blockquote, a paragraph, something else?
The \n (and I've treid \r as well) are trying to do something, it's as
if they just can't really make a new line becuase there isn't a place
for it, maybe?
OK, you're using firstChild of the div which is a text node. So innerHTML won't work.

You need to learn a bit about the document structure and nodes. Use the Firefox browser. Download the Firebug debugger and have a look what's there.

You need to redefine what you actually are trying to achieve. You can insert a new text node at the beginning of the div text:

var t = document.getElementById("text");
var newText = document.createTextNode("new text");
t.insertBefore(newText, t.firstChild);
var br = document.createElement("br");
t.insertBefore(br, newText.nextSibling);
t.removeChid(br.nextSibling);

Take a look at the documentation:

http://www.w3.org/TR/DOM-Level-2-Cor...t-binding.html

Inside a browser, the document is a hierarchical tree structure of Nodes.

HTML tags become Nodes of a special type "Element" which are accessible to javascript. Textual content becomes text Nodes of type "CharacterData".

You can look up nodes, and perform methods on them, see the "Object Node" section.

In the "Object Element" section, are elements which are created from HTML tags. These have all the attributes of Nodes, plus the capabilities listed there.

Study that document - it's the bible for dynamic page manipulation.

Cheers,

Animal
Mar 18 '07 #9
On Mar 18, 2:24 pm, TheBagbournes <n...@noway.comwrote:
alice wrote:
On Mar 18, 11:31 am, "alice" <a...@fearofdolls.comwrote:
On Mar 18, 12:21 am, TheBagbournes <n...@noway.comwrote:
>alice wrote:
On Mar 17, 5:02 pm, scripts.cont...@gmail.com wrote:
alice wrote:
I'm doing some text swapping with javascript, got it working fine, but
I would like the line to have line breaks and being a beginner, I
don't even know if this is possible.
So I have a line like this
swaptext('Shaun, Greg, Violet, Joel, 1999')";
and I would like 1999 to be on a new line. Is there a simple way to do
this? I'd swear I've seen a way, but now I can't seem to find it.
swaptext('Shaun, Greg, Violet, Joel, \n1999')";
will work for text, for HTML -use:
swaptext('Shaun, Greg, Violet, Joel,<br1999')";
Neither of those is working.
the \n creates a space but no line break, and the <brshows up in the
text itself.
The header function is as follows
function swaptext(what)
{document.getElementById("text").firstChild.node Value=what;}
Then I have a div with the id="text".
Use innerHTML instead of nodeValue, and use the <brversion.- Hide quoted text -
- Show quoted text -
When I do that, the text does not swap out at all.- Hide quoted text -
- Show quoted text -
I'm getting the feeling it may have to do with the text that is being
replaced. What I have is
<div id="text">phototext
</div>
And the word phototext is swapped out with the names. Do I need to do
something else with this to allow it to be able to "use" the line
break? I've tried adding a <brand another line of text after
'phototext', but I'm wondering, do I need something else, like for it
to be in a table, a span, a blockquote, a paragraph, something else?
The \n (and I've treid \r as well) are trying to do something, it's as
if they just can't really make a new line becuase there isn't a place
for it, maybe?

OK, you're using firstChild of the div which is a text node. So innerHTML won't work.

You need to learn a bit about the document structure and nodes. Use the Firefox browser. Download the Firebug debugger and have a look what's there.

You need to redefine what you actually are trying to achieve. You can insert a new text node at the beginning of the div text:

var t = document.getElementById("text");
var newText = document.createTextNode("new text");
t.insertBefore(newText, t.firstChild);
var br = document.createElement("br");
t.insertBefore(br, newText.nextSibling);
t.removeChid(br.nextSibling);

Take a look at the documentation:

http://www.w3.org/TR/DOM-Level-2-Cor...t-binding.html

Inside a browser, the document is a hierarchical tree structure of Nodes.

HTML tags become Nodes of a special type "Element" which are accessible to javascript. Textual content becomes text Nodes of type "CharacterData".

You can look up nodes, and perform methods on them, see the "Object Node" section.

In the "Object Element" section, are elements which are created from HTML tags. These have all the attributes of Nodes, plus the capabilities listed there.

Study that document - it's the bible for dynamic page manipulation.

Cheers,

Animal- Hide quoted text -

- Show quoted text -

Thanks, but since I can't decipher anything on that page at all, I
guess I'll have to use a different method. I've decided I can just
repeat what I'm doing and have 3-4 pairs of functions and divs and
swap each line.

Mar 18 '07 #10
On Mar 18, 2:24 pm, TheBagbournes <n...@noway.comwrote:
alice wrote:
On Mar 18, 11:31 am, "alice" <a...@fearofdolls.comwrote:
On Mar 18, 12:21 am, TheBagbournes <n...@noway.comwrote:
>alice wrote:
On Mar 17, 5:02 pm, scripts.cont...@gmail.com wrote:
alice wrote:
I'm doing some text swapping with javascript, got it working fine, but
I would like the line to have line breaks and being a beginner, I
don't even know if this is possible.
So I have a line like this
swaptext('Shaun, Greg, Violet, Joel, 1999')";
and I would like 1999 to be on a new line. Is there a simple way to do
this? I'd swear I've seen a way, but now I can't seem to find it.
swaptext('Shaun, Greg, Violet, Joel, \n1999')";
will work for text, for HTML -use:
swaptext('Shaun, Greg, Violet, Joel,<br1999')";
Neither of those is working.
the \n creates a space but no line break, and the <brshows up in the
text itself.
The header function is as follows
function swaptext(what)
{document.getElementById("text").firstChild.node Value=what;}
Then I have a div with the id="text".
Use innerHTML instead of nodeValue, and use the <brversion.- Hide quoted text -
- Show quoted text -
When I do that, the text does not swap out at all.- Hide quoted text -
- Show quoted text -
I'm getting the feeling it may have to do with the text that is being
replaced. What I have is
<div id="text">phototext
</div>
And the word phototext is swapped out with the names. Do I need to do
something else with this to allow it to be able to "use" the line
break? I've tried adding a <brand another line of text after
'phototext', but I'm wondering, do I need something else, like for it
to be in a table, a span, a blockquote, a paragraph, something else?
The \n (and I've treid \r as well) are trying to do something, it's as
if they just can't really make a new line becuase there isn't a place
for it, maybe?

OK, you're using firstChild of the div which is a text node. So innerHTML won't work.

You need to learn a bit about the document structure and nodes. Use the Firefox browser. Download the Firebug debugger and have a look what's there.

You need to redefine what you actually are trying to achieve. You can insert a new text node at the beginning of the div text:

var t = document.getElementById("text");
var newText = document.createTextNode("new text");
t.insertBefore(newText, t.firstChild);
var br = document.createElement("br");
t.insertBefore(br, newText.nextSibling);
t.removeChid(br.nextSibling);
Where would I insert this, and what exactly would it do?
Take a look at the documentation:

http://www.w3.org/TR/DOM-Level-2-Cor...t-binding.html

Inside a browser, the document is a hierarchical tree structure of Nodes.

HTML tags become Nodes of a special type "Element" which are accessible to javascript. Textual content becomes text Nodes of type "CharacterData".

You can look up nodes, and perform methods on them, see the "Object Node" section.

In the "Object Element" section, are elements which are created from HTML tags. These have all the attributes of Nodes, plus the capabilities listed there.

Study that document - it's the bible for dynamic page manipulation.

Cheers,

Animal- Hide quoted text -

- Show quoted text -

Mar 18 '07 #11
alice wrote:
It's all part of an onclick function
onClick="if (document.images) document.images['blank'].src
= 'images/new.gif'; swaptext('Shaun, Greg, Violet, Joel,
1999')";>
The functions for both the image swap and the text swap are
in the head of the html, and it's all working perfectly. I
just want to know if there is a way to insert a line break
before '1999'. How do I do that when it is already a quote
within a javascript line? I can't just add a <brbefore it.
This code adds <BRbefore the last 4 digits of the string:

<div id="myID">content</div>
<hr>
<a href="#" onClick="swaptext('Paris, 1999'); return false">swap1</a>
<a href="#" onClick="swaptext('1, 2, 3, 2000'); return false">swap2</
a>
<a href="#" onClick="swaptext('a,b,c, 2002'); return false">swap3</a>
<script type="text/javascript">
function swaptext(co)
{
document.getElementById('myID').innerHTML =
co.replace( /\d{4}$/, function (y) { return '<br>'+y } )
}
</script>

The string must end on 4 digits for this to work (which should be
okay, I suppose).

Hope this helps,

--
Bart

Mar 19 '07 #12
Bart Van der Donck wrote on 19 mrt 2007 in comp.lang.javascript:
function swaptext(co){
document.getElementById('myID').innerHTML =
co.replace( /\d{4}$/, function (y) { return '<br>'+y } )
}
co.replace( /(\d{4})$/, '<br>$1')

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 19 '07 #13
On Mar 19, 4:35 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Bart Van der Donck wrote on 19 mrt 2007 in comp.lang.javascript:
function swaptext(co){
document.getElementById('myID').innerHTML =
co.replace( /\d{4}$/, function (y) { return '<br>'+y } )
}

co.replace( /(\d{4})$/, '<br>$1')

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
When using this, nothing gets swapped and it says there is an error on
the page.

Mar 19 '07 #14
On Mar 19, 4:07 am, "Bart Van der Donck" <b...@nijlen.comwrote:
alice wrote:
It's all part of an onclick function
onClick="if (document.images) document.images['blank'].src
= 'images/new.gif'; swaptext('Shaun, Greg, Violet, Joel,
1999')";>
The functions for both the image swap and the text swap are
in the head of the html, and it's all working perfectly. I
just want to know if there is a way to insert a line break
before '1999'. How do I do that when it is already a quote
within a javascript line? I can't just add a <brbefore it.

This code adds <BRbefore the last 4 digits of the string:

<div id="myID">content</div>
<hr>
<a href="#" onClick="swaptext('Paris, 1999'); return false">swap1</a>
<a href="#" onClick="swaptext('1, 2, 3, 2000'); return false">swap2</
a>
<a href="#" onClick="swaptext('a,b,c, 2002'); return false">swap3</a>
<script type="text/javascript">
function swaptext(co)
{
document.getElementById('myID').innerHTML =
co.replace( /\d{4}$/, function (y) { return '<br>'+y } )}

</script>

The string must end on 4 digits for this to work (which should be
okay, I suppose).

Hope this helps,

--
Bart
Well, OK, I got this code to work, sort of, but I don't think it will
ultimately be able to do what I need. I want each thumbnail photo I'm
dealing with to make a few lines of text to appear, Names, then a year
on another line, then photo credits, and maybe a location. I thought
there would just be an easy way to insert a line break into the string
that would show up properly in the div area. I don't know enought
about javascript to know if this is even possible, but so far it would
seem like it is not.

Mar 20 '07 #15
alice wrote on 20 mrt 2007 in comp.lang.javascript:
On Mar 19, 4:35 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>Bart Van der Donck wrote on 19 mrt 2007 in comp.lang.javascript:
function swaptext(co){
document.getElementById('myID').innerHTML =
co.replace( /\d{4}$/, function (y) { return '<br>'+y } )
}

co.replace( /(\d{4})$/, '<br>$1')

When using this, nothing gets swapped and it says there is an error on
the page.
Please show the offending code.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 20 '07 #16
alice wrote:
On Mar 19, 4:07 am, "Bart Van der Donck" <b...@nijlen.com>
wrote:
>[ snip code ]
Well, OK, I got this code to work, sort of, but I don't
think it will ultimately be able to do what I need. I want
each thumbnail photo I'm dealing with to make a few lines
of text to appear, Names, then a year on another line, then
photo credits, and maybe a location. I thought there would
just be an easy way to insert a line break into the string
that would show up properly in the div area. I don't know
enought about javascript to know if this is even possible,
but so far it would seem like it is not.
You should start thinking in more structural patterns. In programming
code you can only instruct commands that are logical and coherent;
otherwise you'll have problems. 1+1 is not "sort of 2" like you say.
It is 2 or not.

Why don't you just adapt the values themselves ? E.g.

swaptext('Shaun, Greg<br>1999<br>Photo by John')

No need for any exotic stuff then and you can add as much/few line
ends as you like per photo. Here is the full code:

<div id="myID">content</div>
<hr>
<a href="#" onClick="swaptext('Paris<br>1999<br>Photo by Alice');
return false">swap1</a>
<a href="#" onClick="swaptext('<big>Party!</big><br>1999');
return false">swap2</a>
<a href="#" onClick="swaptext('John<br>2002<br>New York');
return false">swap3</a>
<script type="text/javascript">
function swaptext(co) {
document.getElementById('myID').innerHTML = co
}
</script>

Hope this helps,

--
Bart

Mar 20 '07 #17
On Mar 20, 3:14 am, "Bart Van der Donck" <b...@nijlen.comwrote:
alice wrote:
On Mar 19, 4:07 am, "Bart Van der Donck" <b...@nijlen.com>
wrote:
[ snip code ]
Well, OK, I got this code to work, sort of, but I don't
think it will ultimately be able to do what I need. I want
each thumbnail photo I'm dealing with to make a few lines
of text to appear, Names, then a year on another line, then
photo credits, and maybe a location. I thought there would
just be an easy way to insert a line break into the string
that would show up properly in the div area. I don't know
enought about javascript to know if this is even possible,
but so far it would seem like it is not.

You should start thinking in more structural patterns. In programming
code you can only instruct commands that are logical and coherent;
otherwise you'll have problems. 1+1 is not "sort of 2" like you say.
It is 2 or not.

Why don't you just adapt the values themselves ? E.g.

swaptext('Shaun, Greg<br>1999<br>Photo by John')
That's exactly what I'm trying to do. I just don't know how. Simply
adding the <brdoes not do it.
No need for any exotic stuff then and you can add as much/few line
ends as you like per photo. Here is the full code:

<div id="myID">content</div>
<hr>
<a href="#" onClick="swaptext('Paris<br>1999<br>Photo by Alice');
return false">swap1</a>
<a href="#" onClick="swaptext('<big>Party!</big><br>1999');
return false">swap2</a>
<a href="#" onClick="swaptext('John<br>2002<br>New York');
return false">swap3</a>
<script type="text/javascript">
function swaptext(co) {
document.getElementById('myID').innerHTML = co
}
</script>

Hope this helps,

--
Bart
I can try this, but this code is different than what I'm using in the
first place. I'm not using anchors, these images are not links, just
thumbnails that make a larger picture appear somewhere else on the
screen when clicked. The only way I figured out to get the text to be
swapped is to have a div tag with a no-break-space as a place holder
next to the image. When I add a <brin the middle of the text and use
innerHTML, nothing happens, no breaks. At least the \n made a space,
but not a line break.

Mar 20 '07 #18
On Mar 20, 9:28 am, "alice" <a...@fearofdolls.comwrote:
On Mar 20, 3:14 am, "Bart Van der Donck" <b...@nijlen.comwrote:


alice wrote:
On Mar 19, 4:07 am, "Bart Van der Donck" <b...@nijlen.com>
wrote:
>[ snip code ]
Well, OK, I got this code to work, sort of, but I don't
think it will ultimately be able to do what I need. I want
each thumbnail photo I'm dealing with to make a few lines
of text to appear, Names, then a year on another line, then
photo credits, and maybe a location. I thought there would
just be an easy way to insert a line break into the string
that would show up properly in the div area. I don't know
enought about javascript to know if this is even possible,
but so far it would seem like it is not.
You should start thinking in more structural patterns. In programming
code you can only instruct commands that are logical and coherent;
otherwise you'll have problems. 1+1 is not "sort of 2" like you say.
It is 2 or not.
Why don't you just adapt the values themselves ? E.g.
swaptext('Shaun, Greg<br>1999<br>Photo by John')

That's exactly what I'm trying to do. I just don't know how. Simply
adding the <brdoes not do it.


No need for any exotic stuff then and you can add as much/few line
ends as you like per photo. Here is the full code:
<div id="myID">content</div>
<hr>
<a href="#" onClick="swaptext('Paris<br>1999<br>Photo by Alice');
return false">swap1</a>
<a href="#" onClick="swaptext('<big>Party!</big><br>1999');
return false">swap2</a>
<a href="#" onClick="swaptext('John<br>2002<br>New York');
return false">swap3</a>
<script type="text/javascript">
function swaptext(co) {
document.getElementById('myID').innerHTML = co
}
</script>
Hope this helps,
--
Bart

I can try this, but this code is different than what I'm using in the
first place. I'm not using anchors, these images are not links, just
thumbnails that make a larger picture appear somewhere else on the
screen when clicked. The only way I figured out to get the text to be
swapped is to have a div tag with a no-break-space as a place holder
next to the image. When I add a <brin the middle of the text and use
innerHTML, nothing happens, no breaks. At least the \n made a space,
but not a line break.- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Hey wait...I think this might work. I'm not at the right computer with
my code now, but on running this program, I can see it now. Just what
does the 'return false' do?

Mar 20 '07 #19
alice wrote:

[snip code]
Hey wait...I think this might work. I'm not at the right
computer with my code now, but on running this program,
I can see it now. Just what does the 'return false' do?
It prevents that the <a hrefcommand is executed. <a href="#">click</
awould get you to the top of the page in some browsers, which is not
the intention here.

--
Bart

Mar 22 '07 #20
On Mar 22, 1:30 am, "Bart Van der Donck" <b...@nijlen.comwrote:
alice wrote:

[snip code]
Hey wait...I think this might work. I'm not at the right
computer with my code now, but on running this program,
I can see it now. Just what does the 'return false' do?

It prevents that the <a hrefcommand is executed. <a href="#">click</
awould get you to the top of the page in some browsers, which is not
the intention here.

--
Bart
Thanks...this is going to accomplish exactly what I wanted :-)

Mar 24 '07 #21

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

Similar topics

6
by: chokky | last post by:
I'm using the mail($MailTo, $Subject, $Body, $headers) function to send out plain text emails, with the message/body being entered via a form. When the email arrives, the message is displayed as a...
1
by: dmiller23462 | last post by:
Hi again guys.... This is my first source of help, by far the best ASP intellectual collective....Thanks in advance for any assistance...Anyway.... The forms I'm still working on (finishing...
1
by: Astra | last post by:
Hi All Could you please let me know how my ASP page can insert 1 row of data containing line breaks into a MySQL DB. To explain, I'm using ASP Classic > MyODBC 3.5x (Win) > MySQL 4 (Win) and...
11
by: Johnny Two Dogs | last post by:
I'm strictly concerned with IE, so cross-browser compatibilty isn't necessary. If you view the code below, I almost get exactly what I'm looking for: - A table of four cells that...
2
by: Brett | last post by:
I'm writing something similar to this into a text file: txtfileError.WriteLine(CurrentDateTime(1) & " Error in Sub Sub1()" & idvar & Chr(10) & Chr(13) & ex.Message) txtfileError.WriteLine() ...
5
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the...
3
by: Wayne Deleersnyder | last post by:
Hi All, I'm trying to create a function that will cause a pop-up alert to appear if dates which were chosen from a drop-down list were invalid on a page. There's 4 dates, so there's the...
1
by: Emma Middlebrook | last post by:
Hi, I've implemented an AJAX update panel on one of my ASP.NET web pages. I generate and add controls to it dynamically. What I would like to do is tell it to start a new line before adding the...
19
by: Samuel Murray | last post by:
G'day everyone I'm trying to find out if there is a way (perhaps using CSS) to let this code: <table><tr><td>One Two Three</td></tr></table> display the same as if the code would have...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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
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,...

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.