victorious
06-27-2012, 03:40 PM
Hello everyone,
I have a .js file where I'm trying to define a function. I want to then call the same function in an HTML page where I will call defined variables within the .js file itself to return a yes/no output. At the bottom of this post is the function itself, taken from another website, and at present when I load the webpage it causes problems.
If you are curious I am using this code to produce a black or white text based on different colors entered and I'm using it as a 'database' for a bunch of different files. To save a great deal of time, I'd like to include this function which would remove the hassle of putting in a yes / no entry for every single file. Thank you for reading.
function brighttest(x)
{
String fontColor = x;
// remove hash character from string
String rawFontColor = fontColor.substring(1,fontColor.length());
// convert hex string to int
int rgb = Integer.parseInt(rawFontColor, 16);
Color c = new Color(rgb);
float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
float brightness = hsb[2];
if (brightness < 0.5) {
var fcolor = "#FFFFFF";
return fcolor;
} else {
var fcolor = "#000000";
return fcolor;
}
}
I have a .js file where I'm trying to define a function. I want to then call the same function in an HTML page where I will call defined variables within the .js file itself to return a yes/no output. At the bottom of this post is the function itself, taken from another website, and at present when I load the webpage it causes problems.
If you are curious I am using this code to produce a black or white text based on different colors entered and I'm using it as a 'database' for a bunch of different files. To save a great deal of time, I'd like to include this function which would remove the hassle of putting in a yes / no entry for every single file. Thank you for reading.
function brighttest(x)
{
String fontColor = x;
// remove hash character from string
String rawFontColor = fontColor.substring(1,fontColor.length());
// convert hex string to int
int rgb = Integer.parseInt(rawFontColor, 16);
Color c = new Color(rgb);
float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
float brightness = hsb[2];
if (brightness < 0.5) {
var fcolor = "#FFFFFF";
return fcolor;
} else {
var fcolor = "#000000";
return fcolor;
}
}