Click to See Complete Forum and Search --> : Any way to write event code to only affect all textboxes?


Vengeance
02-06-2004, 12:29 PM
Hi All,

Still a newbie to Javascript and ASP.net and it shows:)

Anyway, I was wondering if there was an easy way to affect all controls of one type on a form? In that I want to make it that when a textbox gets the focus then it's background turns a light yellow. When the text box loses focus then it's background goes back to being white.

I have a couple global javascript functions that do the changing of colours. However, the only way I can think of getting each and every text to use them would be to add an onFocus() and onBlur() for each control. Is there a way that I could say in just one line something like, for all asp:textbox do this?


TIA,

Brian

AdamGundry
02-07-2004, 03:42 AM
You could perhaps do something like this?

var t = document.getElementsByTagName('input');
for (var i=0;i<t.length;i++){
if (t[i].type = 'text'){
t.onfocus = function(){ ... }
t.onblur = function(){ ... }
}
}

Adam