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: -
<form id="input" method="post" action="<?php echo $PHP_SELF; ?>">
-
Name: <input id="username" type="text" name="username" onkeyup="countdown(username, 10, used)" maxlength="10" size="10" value="<?php echo $_SESSION['username']; ?>" /> Remaining: <input type="text" disabled="disabled" id="used" size="2" value="10" />
-
<br /><br/>
-
<input style="background-color:#1B1B1B; color:#FFFFFF;" id="message" type="text" name="input" size="80" maxlength="75" value="" onkeyup="countdown(input, 75, total)" /> Remaining: <input type="text" disabled="disabled" id="total" size="2" value="75" />
-
<br /> <br />
-
Select Text color:
-
<select name="color">
-
<option value="black" onmousedown="color('message','black')">black</option>
-
<option value="white" onmousedown="color('message','white')">white</option>
-
<option value="blue" onmousedown="color('message','blue')">blue</option>
-
<option value="aqua" onmousedown="color('message','aqua')">aqua</option>
-
<option value="red" onmousedown="color('message','red')">red</option>
-
<option value="yellow" onmousedown="color('message','yellow')">yellow</option>
-
<option value="orange" onmousedown="color('message','orange')">orange</option>
-
<option value="green" onmousedown="color('message','green')">green</option>
-
</select>
-
<input id="submit" type="submit" name="submit" value="Send your message" onclick="check()" />
-
-
</form>
and for the javascript : -
function color(elemID, clr) {
-
-
var table=[];
-
table['red'] = "#FF0000";
-
table['green'] = "#00FF00";
-
table['blue'] = "#0000FF";
-
table['aqua'] = "#00FFFF";
-
table['yellow'] = "#FFFF00";
-
table['orange'] = "#FF7F00";
-
table['black'] = "#DEDEDE";
-
table['white'] = "#F7F7F7";
-
-
-
document.getElementById(elemID).style.color=table[clr];
-
}
-
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
3 2391
I have managed to fix it. =)
So others may learn, please post your solution.
My Chatbox -
//before - old code:
-
function color(elemID, clr) {
-
-
-
var table=[];
-
table['red'] = "#FF0000";
-
table['green'] = "#00FF00";
-
table['blue'] = "#0000FF";
-
table['aqua'] = "#00FFFF";
-
table['yellow'] = "#FFFF00";
-
table['orange'] = "#FF7F00";
-
table['black'] = "#DEDEDE";
-
table['white'] = "#F7F7F7";
-
-
document.getElementById(elemID).style.color=table[clr];
-
}
-
-
//after - new code:
-
-
function color(elemID, clr) {
-
-
var table=[];
-
table['red'] = "#FF0000";
-
table['green'] = "#00FF00";
-
table['blue'] = "#0000FF";
-
table['aqua'] = "#00FFFF";
-
table['yellow'] = "#FFFF00";
-
table['orange'] = "#FF7F00";
-
table['black'] = "#000000";
-
table['white'] = "#FFFFFF";
-
-
document.getElementById(elemID).style.color=table[clr];
-
-
if (clr == "black") {
-
document.getElementById(elemID).style.backgroundColor = "#FFFFFF";
-
}
-
else {
-
document.getElementById(elemID).style.backgroundColor = "#1B1B1B";
-
}
-
//the if statement added isn't part of the solution of the problem, it just aids readability in the text box.
-
}
-
<select name="color">
-
<option value="black" onmousedown="color('message','black')">black</option>
-
<option value="white" onmousedown="color('message','white')">white</option>
-
<option value="blue" onmousedown="color('message','blue')">blue</option>
-
<option value="aqua" onmousedown="color('message','aqua')">aqua</option>
-
<option value="red" onmousedown="color('message','red')">red</option>
-
<option value="yellow" onmousedown="color('message','yellow')">yellow</option>
-
<option value="orange" onmousedown="color('message','orange')">orange</option>
-
<option value="green" onmousedown="color('message','green')">green</option>
-
</select>
-
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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:...
|
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...
|
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 |
+---+---+
|
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"...
|
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...
|
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...
|
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"...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
| |