473,406 Members | 2,343 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,406 software developers and data experts.

Change color of font using javascript

I want change the color on the font to red for the text within the div element.

I have the following code.

[HTML]
<style type="text/css">
.style2 {color: #000000}
</style>
[/HTML]
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/JavaScript">
  2. function radio1(){
  3. document.form1.test12.style.color="#FF0000";}
  4. </script>
[HTML]
<form name="form1" method="post" action="submit.php">
<p class="style2"><input name="radType" type="radio" onClick="radio1()" value="new">Change to red.</p>

<div id="test12"><p class="style2">You agree to the following by checking this box and clicking submit.</p></div>

</form>[/HTML]


I think that is the code, I cut out the extra stuff...My page works fine except changing that font color. please ignore any mistakes i might have made in copying.

I hope this makes sense.
Sep 19 '07 #1
5 3138
gits
5,390 Expert Mod 4TB
hi ...

instead of:

Expand|Select|Wrap|Line Numbers
  1. document.form1.test12
  2.  
use:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('test12')
  2.  
kind regards
Sep 19 '07 #2
hi ...

instead of:

Expand|Select|Wrap|Line Numbers
  1. document.form1.test12
  2.  
use:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('test12')
  2.  
kind regards

I made the change you suggested. Although, I don't receive any errors. I don't get the desired results. I want the text in the html to change to red when the radio button is clicked.
Sep 19 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

there has to be another error ... is the function called?

try this ... that works:

[HTML]
<div id="test" style="color: green;">test</div>
<input type="button" value="red it :)" onclick="document.getElementById('test').style.col or = 'red';"/>
[/HTML]
kind regards
Sep 19 '07 #4
Thank you so much for you help. The only thing i can figure out that was stopping it was the fact that i had the class defined in the <p> tag instead of the <div> tag. At any rate, i have it working now.

Thanks again.
Sep 19 '07 #5
gits
5,390 Expert Mod 4TB
glad to hear you got it working ... post back to the forum anytime you have more quetsions ...

kind regards
Sep 19 '07 #6

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

Similar topics

7
by: Michael Hill | last post by:
I have a perl script that i use to render a html page. In that page i call out a stylesheet. If the user has a 800x600 display the fonts are really too big. Since screen resolution is a function...
5
by: Matt | last post by:
I created 3 hyperlinks, when the user click each link, it will change the color of the text of a link. For example, when user clicks Link1, text Link1 will become red color, but Link2 and Link3...
4
by: Nathan Given | last post by:
Hello All, I am trying to randomly change the background image of my home page but I can't seem to figure it out. Here is a snippet of my css .... BODY {background:transparent...
2
by: Pete Kipe | last post by:
I'm not a JavaScript programmer...but I'm trying to put together a simple menu system for a new website and need a little help. I have the following script: <SCRIPT language=javascript> <!--...
9
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
1
by: roshina | last post by:
Hi Iam facing a problem in my project, developing a web site for online shopping in ASP on windows XP using IIS server. All the validations are ok but the new password is not upadated in the data...
7
by: moondaddy | last post by:
in asp.net 2.0, i have a link buttonand want to change the forecolor in a mouse over event. how can I do this? -- moondaddy@noemail.noemail
18
by: wizdom | last post by:
Help - change text on click - text has another onclick inside with php variables ---------- I think what I'm trying to do is simple. I have a 2 buttons on a page. 1 button allows a thread of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.