halu there!! i'm a 1month experienced java scripter but got a good hang of it already. hehehe.. i developed a "color selection" tool, similar to the one in flash when you choose a color for a graphic, with CSS only. the product is finished. whenever i select a color, its color will be displayed in a box whose id name is contained in variable "color_box" and the equivalent color value will appear in a text box with id contained in the variable "color_text" but only in rgb format.
it's here, check it out: http://glitzy3.com/layouts.php (FIREFOX ONLY)
this.style.backgroundColor returns an RGB value like rgb(255,255,255) but i want it to return a hex value like #FFFFFF. is that possible without having to go through a "RGB2HEX" function? i can't use a function no more because my code seems to be too complex that it won't "fit" or work anymore if i include a function which returns the hex.
this is a part of the script within a function, which receives two values, -
function(color_box, color_text):
-
....
-
var color="this.style.backgroundColor";
-
....
-
color_table = color_table.concat("<td onclick=\"show_color_table(false)\" onmouseover=\"this.style.cursor=\'help\',document.getElementById(\'",color_text,"\').value=",color,",document.getElementById(\'",color_box,"\').style.backgroundColor=",color,"\" style=\"background-color:rgb(");
-
color_table = color_table.concat(R,",",G,",",B,");\"></td>");
....
the bold portion is the problem. i cant use RGBToHEX(color) because the value of color sent to the function RGBToHex will not anymore be the color value but the text "this.style.backgroundColor". so it seems that the variable is far away from getting the actual this.style.backgroundColor if i put a function.
check out my code its in a php document at: http://glitzy3.com/layouts.php (view with FireFox NOT IE)
AH SINCE I DIDN'T REALIZE THAT MY CODE DOENST WORK IN INTERNET EXPLORER, COULD YOU PLEASE GIVE ME THE "SOURCE CODE" IN MY CODE THAT CAUSED THE MISERY?
6 10682
Heya, Fallen Angel. Welcome to TSDN!
Please use CODE tags when posting source code:
[CODE=javascript]
JavaScript code goes here.
[/CODE]
Did you put a '#' in front of the hex code? -
document.getElementById(' ... ').style.backgroundColor = '#' + hexCode;
-
Did you put a '#' in front of the hex code? -
document.getElementById(' ... ').style.backgroundColor = '#' + hexCode;
-
oops, sorry for not putting the <code=javascript> i didnt know hehe..
yeah i used # in front of the hex for the first three table color columns and for the rest i had to use rgb(xxx,yyy,zzz), but EITHER WAY i use, this.style.backgroundColor, will always return rgb(xxx,yyy,zzz) in firefox and #XXYYZZ in IE as i researched. can FF not return #XXYYZZ?
in the bold portion of my code in color, i tried passing color in function like this: RGBToHex(color)
and if i use function as: -
function RGBToHEX(str){
-
return str;
-
}
-
it just works fine in that it just returns the passed value. BUT if i try to put methods on function variable "str" like:
str = str.slice(4) (which is supposed to return xxx,yyy,zzz) with rgb( stripped off,
then it will never return anything. i tried any string methods, it won't return anything.
Maybe it has something to do like when i receive a color rgb(xxx,yyy,zzz), it cannot be edited as string. do i have to convert it to a string or something to be able to apply string methods to it?
ah nevermind.. it's ok, i solved it, i included the RGBToHex into the string instead of concatenating it. this is the way i did it (bold part): -
color_table = color_table.concat("<td onclick=\"show_color_table(false)\" onmouseover=\"this.style.cursor=\'help\',document.getElementById(\'",color_text,"\').value=RGBToHEX(",color,"),document.getElementById(\'",color_box,"\').style.backgroundColor=",color,"\" style=\"background-color:rgb(");
-
color_table = color_table.concat(R,",",G,",",B,");\"></td>");
-
the problem now is that my product does not work in IE. does IE even support javascript. or what is wrong with my code that makes it not work in IE?
Have a look at this. -
function RGBtoHEX(str)
-
{
-
var arr = str.split(",");
-
var r = arr[0].substring(4),
-
g = arr[1],
-
b = arr[2].substring(0,arr[2].length-1);
-
return "#"+r+g+b;
-
}
-
Good Luck!
Kind regards,
Dmjpro.
wow!! i didn't know that the split function was that powerful, in fact its the first time i used it. hehehe...
i just added an additional function that converts your #255255255 to #FFFFFF
with the DECToHex function: -
-
return "#" + DECToHEX(r) + DECToHEX(g) + DECToHEX(b)
-
-
function DECToHEX(N) {
-
hex_set = "0123456789ABCDEF"
-
return hex_set.charAt((N-N%16)/16) + hex_set.charAt(N%16);
-
}
-
thanx alot DMJPRO for that very efficient code!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: joealey2003 |
last post by:
Hi all...
I included a css file on my html and i need to check some properties.
The html is: <style id="myid" src="mycsspage.css"> </style>
Now i need something to access it like:
...
|
by: Jane D |
last post by:
I have got a bookmarklet for use with Opera which highlights all
occurrences of some text in the displayed page. I find it very
useful.
Sometimes I need to use two or three different colours...
|
by: Martin |
last post by:
I have some functions in a script in which I'm manipulating the
innerText and background colors of certain rows in a table. The lines
below work OK in IE but when I try them in Mozilla, I get an...
|
by: J.Marsch |
last post by:
All:
I have an interesting problem in front of me. does this sound reasonable,
or ridiculous?
I have to build something that is sort of like a style sheet for Windows
controls.
Picture a...
|
by: SpamProof |
last post by:
I got an animated gif that is a barber pole spinning that I want to
use as a progress bar.
The problem is that is stops spinning (shows 1 frame) when my browser
is processing a submited request...
|
by: Jim Carlock |
last post by:
Does a SELECT element (listbox) need to be inside
a FORM element?
The code I'm playing with:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"...
|
by: Alex |
last post by:
Trying to change a few tags by swapping color values to my own. It
doesn't give any error, yet it doesn't perform. Is there an error in my
logic somewhere?
var my_i =...
|
by: pld888 |
last post by:
https://turbotaxweb.turbotaxonline.intuit.com/open/registration/SignIn.htm
anyone know which 3rd party textbox this is???
|
by: Piotr K |
last post by:
Ok, I tried simply everything that came to my mind and now I ran out
of ideas, but to the point - take a look at the code below
// GetStyle returns given style value (works fine)...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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...
|
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: 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...
|
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: 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...
| |