Help changing color of text box in HTML with Javascript?

Question by Matt D: Help changing color of text box in HTML with Javascript?
I have a text-input box. It has an onchange method attached to it that fires a function in my Javascript. The functions takes the text-input box as its argument. I want to change the color of the text-input box that called the function. Here is a snippet:

function check_guess (o, row, col) {
document.getElementsByName(“o.name”).style=”background-color: #72A4D2;”
}

Why isn’t the box changing color?

Best answer:

Answer by Michael
Your javascript function has been truncated by Y! Answers so I can’t tell everything that is causing problems.

One thing I can say is that #72A4D2 should be in quotes – “#72A4D2″.

Also if you are passing “this”, there is no need to locate the Element using a document method. You already have the Element.

Here is a simplified version of your code that works:

"http://www.w3.org/TR/html4/loose.dtd" >




Change Input Colour


Know better? Leave your own answer in the comments!

Revisions

There are no revisions for this post.

Tags: , , , , ,

No comments yet.

Leave a Reply