It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Add css class to field if another is completed

Add css class to field if another is completed

Postby UNarmed on Mon Feb 01, 2010 9:49 am

Hey i am new to the site and i was wondering whether anyone could give me a hand here =] The title pretty much discribes the problem i am having. How would i go about adding a css class to field when another field is completed?

I need to get this done for validation purposes but so far i am totaly at a loss as to getting this right. Help would be greatly appreciated!
UNarmed
 
Posts: 2
Joined: Mon Feb 01, 2010 9:44 am

Re: Add css class to field if another is completed

Postby harrierdh on Mon Feb 01, 2010 4:52 pm

I think this is what you are asking. You reference the css class attribute like this in javascript.
<script>
document.getElementById( "divtwo" ).className = "newclass";
</script>
<div id="divtwo" class="oldclass" >&nbsp;</div>
harrierdh
50+ Club
 
Posts: 51
Joined: Wed Dec 16, 2009 7:04 pm

Re: Add css class to field if another is completed

Postby UNarmed on Tue Feb 02, 2010 7:00 am

Ok great thanks for the reply =]

How would i trigger this when someone enters text into a specific textfield though?
UNarmed
 
Posts: 2
Joined: Mon Feb 01, 2010 9:44 am

Re: Add css class to field if another is completed

Postby harrierdh on Tue Feb 02, 2010 2:39 pm

There are several events you can capture on any given html tag. Including onClick, onKeyPress, onBlur, onMouseOver etc.

The example below captures the onClick event in a button.

<script>
function changeClassName() {
document.getElementById( "divtwo" ).className = "newclass";
}
</script>
<div id="divtwo" class="oldclass" >&nbsp;</div>
<input type="button" id="mybutton" onClick="changeClassName()" />
harrierdh
50+ Club
 
Posts: 51
Joined: Wed Dec 16, 2009 7:04 pm

Re: Add css class to field if another is completed

Postby iDad on Tue Feb 02, 2010 3:11 pm

Well done harrierdh.
PHOTO EDITING
Image
User avatar
iDad
1000+ Club
 
Posts: 1890
Joined: Fri Jul 17, 2009 6:05 pm
Location: USA


Who is online

Users browsing this forum: No registered users and 8 guests