/    Sign up×
Community /Pin to ProfileBookmark

Any way to write event code to only affect all textboxes?

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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@AdamGundryFeb 07.2004 — 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
×

Success!

Help @Vengeance spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...