0

A followup question to my previous thread: Disable some html output in input box

I just noticed that everytime I add a space in my input, a line break is automatically added (basically the equivilant of <br> in html.

So if I typed Hello I am John in the input, the output would return:

Hello
I 
Am
John

I just want the input to space the text and not add a <br> So Hello I am John would be Hello I am John as it should be.

Hope I made things clear,

Thanks!

Community
  • 1
  • 1
WalkOfLife
  • 267
  • 1
  • 4
  • 14

3 Answers3

1

It was just a margin problem that was pushing my text.

WalkOfLife
  • 267
  • 1
  • 4
  • 14
0

You can had a space just type &nbsp;

So If u want to type whitespaces without the <br> problem you need to do a javascript function that replace spaces by &nbsp;

function removeSpaces()  {
   var str = document.getElementById("input").innerHTML; 
   var res = str.replace(/\s/gi, "&nbsp;");
   document.getElementById("input").innerHTML=res;
} 
  • 1
    Here's part of my code, it still isn't work for me: http://jsfiddle.net/5Z2Jb/ I appreciate your help though and hope that you can help me fix this. – WalkOfLife Mar 30 '14 at 21:30
0

write your code as follows

Hello &nbsp; I &nbsp; am &nbsp; John
Anubhav
  • 7,138
  • 5
  • 21
  • 33