How to change background color of a textarea using JavaScript -


I just want to know how I can change the color of the color of the color of the text in a text box I am able to paint, font and shape text, but the background does not seem to work in the same way. My code for text color and background is:

script:

  function set color (where, color) {if (where == "background color") document .getElementById ('Textarea'). Style.backgroundColor = Color; If (where == "color text") document.getElementById ('textarea'). Style.color = Color; }   

HTML:

  & lt; P & gt; Card color: & lt; Input type = "text" name = "backgroundcolour" size = "10" onchange = "setcolor ('backgroundcolour', this.value)" & gt; & Lt; Br> Text color: & lt; Input type = "text" name = "colourtext" size = "10" onchange = "setColor ('colourtext', this.value)" & gt; & Lt; Br> & Lt; / P & gt; & Lt; Textarea id = 'textarea' name = "data" cols = "100" rows = "10" & gt; & Lt; / Text field & gt;   

It seems that my internet was blocking the script, so it could not change the background

Your code is actually working, maybe you forgot to remove the focus from the text box to trigger the change event.

function set collar (where, color) {if (where == "background color") document.getElementById ('Textarea'). Style.backgroundColor = Color; If (where == "color text") document.getElementById ('textarea'). Style.color = Color; }
  & lt; P & gt; Card color: & lt; Input type = "text" name = "backgroundcolour" size = "10" onchange = "setcolor ('backgroundcolour', this.value)" & gt; & Lt; Br> Text color: & lt; Input type = "text" name = "colourtext" size = "10" onchange = "setColor ('colourtext', this.value)" & gt; & Lt; Br> & Lt; / P & gt; & Lt; Textarea id = 'textarea' name = "data" cols = "100" rows = "10" & gt; & Lt; / Textarea & gt;      

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -