You are not logged in.

  • Login

Dear visitor, welcome to Coder Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, November 30th 2007, 9:13am

<br> mit innerHTML in einem <span> ausgeben

Hallo Leute,

ich brauche mal wieder eure Hilfe!
Ich habe ein Textfeld, ein Span-Kontainer:

<textarea name="newsflash" rows="4" id="newsflash" style="width:400px" onChange="updateNewsflash(this, event)" onKeyUp="updateNewsflash(this, event)"><?php echo $newsflash; ?></textarea><span id="vorschauNewsflash"></span>

und folgendes javascript:

JavaScript Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function updateNewsflash(input, event) 
{ 
if (input.id == "newsflash") 
{ 
var namespan = document.getElementById("vorschauNewsflash"); 
if (namespan.firstChild == null) 
{ 
namespan.innerHTML = input.value; 
} 
else 
{ 
namespan.firstChild.nodeValue = input.value; 
} 
} 
}


Wie bekomme ich es hin, dass wenn ich einen Zeilenumbruch im Textfeld mache, dieser auch im Span-Kontainer ausgegeben wird? Im Moment macht der IE einen Tab und der FF ein Leerzeichen.

ich hoffe Ihr könnt mir helfen!

Grüße KMD

2

Friday, November 30th 2007, 10:42am

du suchst vermutlich sowas wie nl2br für JavaScript ;)
Ich glaube sowas bietet JavaScript nicht. Also bleiben reguläre Ausdrücke:

JavaScript Code

1
2
3
function updateNewsflash(input, event)  { 
	document.getElementById('vorschauNewsflash').innerHTML = input.value.replace(/\r\n|\r|\n/g,"<br/>");
}

3

Friday, November 30th 2007, 5:32pm

Hi dOnut,

ich Danke dir! Hat mir weiter geholfen!

Similar threads

Social bookmarks