473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Change class attribute onclick

I am trying to create a javascript that will change the color of text for the label of a form field on a the click of a button. I have come up with something, but it doesn't seem to work. Any suggestion?

[HTML]<html>
<head>

<style type="text/css">
.my_red { color: #ff0000 }
.my_green { color: #00ff00 }
.my_blue { color: #0000ff }
.my_black { color: #000000 }
</style>


<script language="JavaScript">

function change_color()
{
function change_fname()
{
var v_obj;
var v_attribute_list;
var v_class;
v_obj=document.getElementById('id_fname');
v_attribute_list=v_obj.attributes;
v_class=v_attribute_list.getNamedItem("class");
v_class.value="my_red"
};
change_fname();
function change_ssn()
{
var v_obj;
var v_attribute_list;
var v_class;
v_obj=document.getElementById('id_ssn').class="my_ green";
v_attribute_list=v_obj.attributes;
v_class=v_attribute_list.getNamedItem("class");
v_class.value="my_green"
};
change_ssn();
function change_phone()
{
var v_obj;
var v_attribute_list;
var v_class;
v_obj=document.getElementById('id_phone');
v_attribute_list=v_obj.attributes;
v_class=v_attribute_list.getNamedItem("class");
v_class.value="my_blue"
};
change_phone();
}

</script>
</head>

<body>

<div id="id_form"
<div id="id_fname" class="my_black">First name</div>
<input name="name" type="text" size="25"/>
<div id="id_ssn" class="my_black">SSN</div>
<input name="SSN" type="text" size="9"/>
<div id="id_phone" class="my_black">Phone</div>
<input name="Phone" type="text" size="9"/>
<hr>
<input type="button" onclick="change_color()">

</div>

</body>

</html>[/HTML]
Oct 25 '07 #1
2 6835
why dont you try something like:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('id_phone').className = "my_red"
?
Oct 25 '07 #2
Thanks for your help!
Oct 25 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: KS | last post by:
Just to show some code to show the consept. <img id="date" onclick="javascript:show_calendar();" src="/PlexSysWeb/images/show-calendar.gif" width=20 height=18 border=0> What i want the...
3
by: webdev | last post by:
Hi, Code below dynamically adds an input box to a form, creating a new name attribute as it goes... (many thanks to Martin Honnen for getting me this far ;0) Problem is - in IE5.5 only the first...
1
by: Jing You | last post by:
hi every one, I have got some confused problem when I try to write some custom object by javascript. Look at the example code here: <BODY> <script language="jscript">
15
by: Encapsulin | last post by:
Hello everybody. I'm trying to change src of quicktime embedded object with javascript: <html><body> <script language="JavaScript"> function Exchange() { document.qtvr.src = "sample2.pano";...
16
by: Giggle Girl | last post by:
Hi there, I have a nav tree similar to the XP Windows Explorer in behavior. It uses styles to underline a row on mouseover, and change the look of a row when clicked. Currently, it is working...
7
by: Giacomo | last post by:
I work on a page structured like: <h2> ... </h2> <div ="div1" class="show"> ... </div> <h2> ... </h2> <div id="div2" class="show"> ... </div> <h2> ... </h2> <div id="div3" class="show">...
10
by: apparker | last post by:
I'm creating a new GUI for a program and it is for a medical exam. There are so many different things to ask someone during a history it wastes too much space to make checkboxes for everything so I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.