0

I have added one text box . I am getting the text entered text box like :

 var text = document.getElementById("textarea").value;

then by using split function I am getting one particular String from say first string from the text . And tried to apply string properly on that like :

 var split = text.split(" ");
 var word = split[0];
 word.italics();

then I formed text again with changed properties of first string and reassigned it to the text box

document.getElementById("textarea").value = text;

but those string properties are not applying to the word . same issue with all string properties like font color ,link etc . I dont know whats wrong I am doing ?

V-Xtreme
  • 7,230
  • 9
  • 39
  • 79
  • 4
    You cannot format text in a textbox – mplungjan Jan 20 '14 at 09:48
  • 1
    @V-Xtreme Hi, I know its not a place to ping you. But, I m really stuck with something on which you have worked earlier. http://stackoverflow.com/questions/20469242/implement-airplay-software-receiver-in-android-os?rq=1. – Kanak Sony Jan 21 '14 at 17:34

2 Answers2

2

You cannot format text in a textbox

Try

document.getElementById("someContainerLikeADivOrSpan").innerHTML=text

For example

Live Demo

window.onload=function() {
  document.getElementById("text").onkeyup=function() {
    var text = this.value;
    var split = text.split(" ");
    var word = split[0];
    document.getElementById("output").innerHTML=word.italics();
  }
}

using

<textarea id="text" placeholder="type some words"></textarea>
<span id="output"></span>
animuson
  • 53,861
  • 28
  • 137
  • 147
mplungjan
  • 169,008
  • 28
  • 173
  • 236
2

You should use a div,span or p element to get the italics word. Try this,

HTML

<textarea id="textarea">test the italics now.</textarea>
<div id="div"></div>

SCRIPT

text=text.replace(word,word.italics());// replace the first word with italics
document.getElementById("div").innerHTML = text;// use div not textarea

Demo

animuson
  • 53,861
  • 28
  • 137
  • 147
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106