473,666 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change color of font using javascript

3 New Member
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">Cha nge 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 3152
gits
5,390 Recognized Expert Moderator Expert
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
abhubbart
3 New Member
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 Recognized Expert Moderator Expert
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="docume nt.getElementBy Id('test').styl e.color = 'red';"/>
[/HTML]
kind regards
Sep 19 '07 #4
abhubbart
3 New Member
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 Recognized Expert Moderator Expert
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
14534
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 of the client and I have this javascript ot detect the srecc size: function ck_res() { if ( (screen.width != 1024) && (screen.height != 768) ) {
5
35222
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 unchange. Here's my attempts, any ideas?? <script language="javascript"> function changecolor (i) { document.i.fontcolor = red; }
4
44324
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 url(../images/homepagebg3.jpg) no-repeat; font:normal 90% Arial, Helvetica, sans-serif; color:#263158;}
2
6158
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> <!-- Hide JavaScript from Java-Impaired Browsers function NavRollOver(oTd) {if (!oTd.contains(event.fromElement)) {oTd.bgColor="#CC0000";}} function NavRollOut(oTd) {if (!oTd.contains(event.toElement))
9
3770
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 body like <br><br> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1>
10
6078
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 button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
1
7424
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 base and also showing a error page. the operating system we used is Windows XP, the source code is ASP, front end we used - HTML and javascript and vb script for validations. the inputs we used are : old pasword :
7
21814
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
7761
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 messages to be displayed, the other button collapses that same thread. Works fine. I was asked if I can just make it one button. I've played around with a few java scripts. they seem to all work fine until i put my added codes in the text line...
0
8869
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.