/    Sign up×
Community /Pin to ProfileBookmark

Help with attributes

Hi,

I have this statement in ASP.NET

txtDirName1First.Attributes.Add(“onclick”, “if(this.value == ‘first’) {this.value = ”; this.color=’#FFF;’}”)

txtDirName1First is an ASP.NET textbox I want to change the color of its font when its clicked.

The first part of my javascript works fine and the textbox clears, however the color doesn’t change.

Thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledMar 23.2009 — i'm not familiar with asp.net, but what i can see is that the code set an event, and of course, the code is javascript. so, this line is wrong because there is no [b]color[/b] property. notice the addition of [b]style[/b] object:
<i>
</i>this.[b]style[/b].color='#FFF';
Copy linkTweet thisAlerts:
@ChilliLimeauthorMar 23.2009 — Hi,

Okay I changed it to this, but the second statement still doesn't seem to work.

if(this.value == 'first') {this.value = ''; this.style.color='#000;'}

Thanks
Copy linkTweet thisAlerts:
@ZeroKilledMar 23.2009 — notice that my original code is different from yours:<i>
</i>//my code;
this.style.color='#000'[b];[/b]
//your code;
this.style.color='#000[b];[/b]'


i did not included the semicolon inside the string [b]'#FFF'[/b].
Copy linkTweet thisAlerts:
@ChilliLimeauthorMar 23.2009 — That works!

Thank you!
×

Success!

Help @ChilliLime 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.19,
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,
)...