/    Sign up×
Community /Pin to ProfileBookmark

Problem with Javascript

I have a javascript that changes the textbox style upon focus and blur events.

I want the javascript to only change the style on the textbox if the textboxes style IS NOT set to “errorfld”

I have tried this but its not working

[CODE]
function DoFocus(fld) {

if (!(fld.classname == ‘errorfld’))
{
fld.className = ‘focusfld’;
}
}
[/CODE]

On the page, i have 3 textboxes, 2 have their cssclass set to normalfld, and 1 has the cssclass set to errorfld, when I set focus to the box that is set to errorfld, the style still changes.

Here is the HTML Source from the browser

[code=html]

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” >
<head><title>

</title>

<style type=”text/css”>
.normalfld
{
background-color: #FFFFFF;
border-top: 1.75px solid #999999;
border-bottom: 1.75px solid #999999;
border-left: 1.75px solid #999999;
border-right: 1.75px solid #999999;
}

.focusfld
{
background-color: #FFFFFF;
border-top: 2px solid #3399FF;
border-bottom: 2px solid #3399FF;
border-left: 2px solid #3399FF;
border-right: 2px solid #3399FF;

}

.errorfld
{
background-color: #FFFFFF;
border-top: 2px solid #FFB000;
border-bottom: 2px solid #FFB000;
border-left: 2px solid #FFB000;
border-right: 2px solid #FFB000;

}
</style>

</head>
<body onload=”fnOnLoad()”>
<form name=”form1″ method=”post” action=”Default.aspx” id=”form1″>

<script src=”Scripts/TBoxHighlighting.js” type=”text/javascript”></script>

<input name=”TextBox1″ type=”text” id=”TextBox1″ class=”normalfld” style=”width:219px;” />
<br />
<br />
<input name=”TextBox2″ type=”text” id=”TextBox2″ class=”normalfld” style=”width:219px;” />
<br />
<br />
<input name=”TextBox3″ type=”text” id=”TextBox3″ class=”[B]errorfld[/B]” style=”width:219px;” />
<br />

</form>
</body>
</html>
[/code]

Any ideas whats wrong??

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Oct 21.2009 — look at your code closely.

Look at the if statement, look at the code that sets the class.

Eric
Copy linkTweet thisAlerts:
@mattstacksauthorOct 22.2009 — I dont want to play hide and seek, can you just tell me what I did wrong?

I just started learning java yesterday so I dont know what im doing wrong.

I would appreciate any help u can give me.

Thanks!

~Matt
Copy linkTweet thisAlerts:
@mattstacksauthorOct 22.2009 — I only want to set the class name to 'focusfld' if it does not equal 'errorfld'

Is that not the correct syntax?
Copy linkTweet thisAlerts:
@A1ien51Oct 22.2009 — Java != JavaScript

There is 6 words there, it is not that hard. Look at it and see what is different.

Eric
Copy linkTweet thisAlerts:
@mattstacksauthorOct 22.2009 — Like I said.. Im new to javascript and I dont see what your thinking I should so I guess ill just let it go.
Copy linkTweet thisAlerts:
@mattstacksauthorOct 22.2009 — I have also tried this

[CODE]function DoFocus(fld) {

if (!(fld.classname = 'errorfld'))
{
fld.className = 'focusfld';
}[/CODE]


And it doesnt work at all.
Copy linkTweet thisAlerts:
@mattstacksauthorOct 22.2009 — how hard would it have been to tell me that the flippin "N" needed to be uppercase.

I thought this was a programming forum where people came for help.

how stupid!
Copy linkTweet thisAlerts:
@mattstacksauthorOct 22.2009 — quite rediculous..
Copy linkTweet thisAlerts:
@thraddashOct 22.2009 — Lol, they are just trying to help you help yourself. You will benefit more that way.

[CODE]function DoFocus(fld) {
if (fld.className != 'errorfld') {
fld.className = 'focusfld';
}
}[/CODE]
Copy linkTweet thisAlerts:
@mattstacksauthorOct 22.2009 — Yeah, that doesnt really make much sense to me.

Why not just say "Hey man, being that your new to javascript, you should know that its case sensitive, and that your 'n' needs to be capitalized."

I would have learned that lesson the same way, but much faster.

And that is why I came to this forum, and posted a thread. Was because I wanted help.
×

Success!

Help @mattstacks 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.24,
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,
)...