Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onfocus event to change background colour 1

Status
Not open for further replies.

slowfish

Programmer
Aug 21, 2009
28
GB
hi

very simple but I can't seem to get an onfocus event to work - changing the background colour of a text box.

function setStyle(x)
{
document.getElementById(x).style.background="yellow";
}

and then the following in the td tags

onfocus="setStyle(this.id) id="iprange"

Any help gratefully received.
 
onfocus="setStyle(this.id) id="iprange"

you forgot to close the onfocus event with double quotes

Code:
<script>
function setStyle(x)
{
    document.getElementById(x).style.background="yellow";
}
</script>

<input type="text" onfocus="setStyle(this.id)" id="iprange" />

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Doh! I think it was a case of looking at it for so long that I didn't spot the obvious!

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top