473,385 Members | 1,610 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,385 software developers and data experts.

Change colour of text in element

118 100+
Hi all,

On one page of my site I have a form (code below) with an input textbox with the id "message". You type in your message in this field (as the id suggests) and depending on an option in a select element (still part of the form) the text of 'message box' changes to that colour.

form:
Expand|Select|Wrap|Line Numbers
  1. <form id="input" method="post" action="<?php echo $PHP_SELF; ?>">
  2. Name: <input id="username" type="text" name="username" onkeyup="countdown(username, 10, used)" maxlength="10" size="10" value="<?php echo $_SESSION['username']; ?>" /> &nbsp;&nbsp;&nbsp; Remaining: <input type="text" disabled="disabled" id="used" size="2" value="10" />
  3. <br /><br/>
  4. <input style="background-color:#1B1B1B; color:#FFFFFF;" id="message" type="text" name="input" size="80" maxlength="75" value="" onkeyup="countdown(input, 75, total)" /> &nbsp;&nbsp;&nbsp; Remaining: <input type="text" disabled="disabled" id="total" size="2" value="75" />
  5. <br /> <br />
  6. Select Text color:
  7.  <select  name="color">
  8. <option value="black" onmousedown="color('message','black')">black</option>
  9. <option value="white" onmousedown="color('message','white')">white</option>
  10. <option value="blue" onmousedown="color('message','blue')">blue</option>
  11.  <option value="aqua" onmousedown="color('message','aqua')">aqua</option>
  12. <option value="red" onmousedown="color('message','red')">red</option>
  13. <option value="yellow" onmousedown="color('message','yellow')">yellow</option>
  14. <option value="orange" onmousedown="color('message','orange')">orange</option>
  15. <option value="green" onmousedown="color('message','green')">green</option>
  16.   </select>
  17. <input id="submit" type="submit" name="submit" value="Send your message" onclick="check()" />
  18.  
  19. </form>
and for the javascript:

Expand|Select|Wrap|Line Numbers
  1. function color(elemID, clr) {
  2.  
  3. var table=[];
  4. table['red'] = "#FF0000";
  5. table['green'] = "#00FF00";
  6. table['blue'] = "#0000FF"; 
  7. table['aqua'] = "#00FFFF";
  8. table['yellow'] = "#FFFF00";
  9. table['orange'] = "#FF7F00";
  10. table['black'] = "#DEDEDE";
  11. table['white'] = "#F7F7F7";
  12.  
  13.  
  14. document.getElementById(elemID).style.color=table[clr];
  15. }
  16.  
Every single one works, except for white. If you type and select 'blue' - the text turns blue (in FireFox anyway), if you choose 'green' then the text turns green.

But if you choose 'white' nothing changes.. I can't for life of me work out what's wrong. Can you guys see anything wrong?

Thanks, Sam
Oct 28 '07 #1
3 2391
helraizer1
118 100+
I have managed to fix it. =)
Oct 29 '07 #2
drhowarddrfine
7,435 Expert 4TB
So others may learn, please post your solution.
Oct 29 '07 #3
helraizer1
118 100+
My Chatbox

Expand|Select|Wrap|Line Numbers
  1. //before - old code:
  2.     function color(elemID, clr) {
  3.  
  4.  
  5.       var table=[];
  6.       table['red'] = "#FF0000";
  7.       table['green'] = "#00FF00";
  8.       table['blue'] = "#0000FF";
  9.       table['aqua'] = "#00FFFF";
  10.       table['yellow'] = "#FFFF00";
  11.       table['orange'] = "#FF7F00";
  12.       table['black'] = "#DEDEDE";
  13.       table['white'] = "#F7F7F7";
  14.  
  15.       document.getElementById(elemID).style.color=table[clr];
  16.       }
  17.  
  18. //after - new code:
  19.  
  20. function color(elemID, clr) {
  21.  
  22. var table=[];
  23. table['red'] = "#FF0000";
  24. table['green'] = "#00FF00";
  25. table['blue'] = "#0000FF"; 
  26. table['aqua'] = "#00FFFF";
  27. table['yellow'] = "#FFFF00";
  28. table['orange'] = "#FF7F00";
  29. table['black'] = "#000000";
  30. table['white'] = "#FFFFFF";
  31.  
  32. document.getElementById(elemID).style.color=table[clr];
  33.  
  34. if (clr == "black") {
  35. document.getElementById(elemID).style.backgroundColor = "#FFFFFF";
  36. }
  37. else {
  38. document.getElementById(elemID).style.backgroundColor = "#1B1B1B";
  39. //the if statement added isn't part of the solution of the problem, it just aids readability in the text box.
  40. }

Expand|Select|Wrap|Line Numbers
  1.  <select  name="color">
  2. <option value="black" onmousedown="color('message','black')">black</option>
  3. <option value="white" onmousedown="color('message','white')">white</option>
  4. <option value="blue" onmousedown="color('message','blue')">blue</option>
  5. <option value="aqua" onmousedown="color('message','aqua')">aqua</option>
  6. <option value="red" onmousedown="color('message','red')">red</option>
  7. <option value="yellow" onmousedown="color('message','yellow')">yellow</option>
  8. <option value="orange" onmousedown="color('message','orange')">orange</option>
  9. <option value="green" onmousedown="color('message','green')">green</option>
  10.   </select>
  11.  
The only way I got it to work is copy the same code from another version of my chatbox, on my site. Which for some reason did work. Both codes look rather similar, yet one works (new) and the other doesn't (old). Can you see why?
Oct 29 '07 #4

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

Similar topics

6
by: Louise | last post by:
Hi I have written an HTML pages which does not have any colour specifying tags as far I know. When I view this in an Microsoft internet explorer browser it appears with a white background and...
4
by: Werner Partner | last post by:
I'm looking for something like that: http://www.sonoptikon.de/praxis-mt/test.php The text should have a certain indent, and from the left border should come a "marker" which goes over the text...
7
by: miked | last post by:
Hi, On a webpage I'm authoring I'm having a problem with setting the text background colour. I'm using this: P {color ="FFFFFF"; background-color:"000000"; font-size:10pt; font-family:...
7
by: kroger | last post by:
Hi, one part of my website is at: http://www.psych.nmsu.edu/~jkroger/lab/undergrads.html I want to make the date at the top right darker blue. But when I do that, all the light blue text...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
18
by: Denny Schierz | last post by:
hi, i want to change my link colors in the p class="suchen": That is my html: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//DE"...
1
by: kaushik | last post by:
hi there, i am not able to change the color of Groupname in panel control from blue to black. I read somewhere, if i set the forecolour of the panel, both the groupingtext and text are rendered...
4
by: html | last post by:
Hello all, I need to change the colour of my text. For the paragraph I do document.fgColor ="blue" ; but how do I do this for the select tags? ....and I prefer it to apply to all select tags...
4
by: sgxbytes | last post by:
Hi, My html has <Table style="year-button-archive" width="60%" > <tr> <td class="gold" > <a title="year">By Year:</a> <td class="gold"> <a id = "2008"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.