Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:15:08+00:00 2026-06-04T22:15:08+00:00

hello im working on a html color maker and found a javascript somewhere only

  • 0

hello im working on a html color maker and found a javascript somewhere only this script deosnt clear out the output when you press make code

so my questions is what do i have to add to my code so it clears the output before putting in the new results

here is my javascript :

function is_valid(color_list)
{
var colors = (color_list.toLowerCase()).split(',');
var hex    = '0123456789abcdef';
var valid  = true;

for (var i = 0; (i < colors.length) && valid; i++)
{
    if (colors[i].length != 6) valid = false;

    for (var j = 0; j < colors[i].length; j++)
    {
        if (hex.indexOf(colors[i].charAt(j)) < 0) valid = false;
    }
}

return valid;
}

function hex_to_dec(n)
{
// n will always be passed in as a string

var c = '0123456789abcdef';

n = n.toLowerCase();

return c.indexOf(n.charAt(0)) * 16 + c.indexOf(n.charAt(1));
}

function hex_to_rgb(hex)
{
// hex will always be passed in as a string

var srgb = '';

for (var i = 0; i < 6; i += 2)
    srgb = srgb + hex_to_dec(hex.substring(i, i + 2)) + ',';

return srgb.substring(0, srgb.length - 1);
}

function two_color_fade(txt, color1, color2)
{
var htm = '';

if (txt.length == 0) return htm;

// color1 and color2 are strings from the comma delimited color_list

// s1 and s2 are now in form 255,00,33

var s1 = hex_to_rgb(color1);
var c1 = s1.split(',');

var s2 = hex_to_rgb(color2);
var c2 = s2.split(',');

for (var i = 0; i < 3; i++)
{
    c1[i] = parseInt(c1[i]);
    c2[i] = parseInt(c2[i]);
}

var inc = new Array(3);

for (var i = 0; i < 3; i++)
{
    if (txt.length - 1 > 0)
    {
        inc[i] = (c2[i] - c1[i]) / (txt.length - 1);
    }
    else
        inc[i] = c2[i];
}

for (var i = 0; i < txt.length; i++)
{
    htm = htm + '<font color="' + rgb_to_hex(c1[0], c1[1], c1[2]) + '">' + txt.charAt(i) + '<\/font>';

    // test print out
    //htm += '<font color="' + rgb_to_hex_wtv(c1[0], c1[1], c1[2]) + '">' +
    //i + ': ' + c1[0] + ',' + c1[1] + ',' + c1[2] + '<\/font><br>';

    for (var j = 0; j < 3; j++) c1[j] += inc[j];
}

return htm;
}

function multi_color_fade(txt, color_list)
{
var htm = '';
var color_count = 0;
var chunk_count = 0;
var chunks = new Array();

var colors = (color_list.toLowerCase()).split(',');

var num_chunks = colors.length - 1;

var quotient  = Math.floor(txt.length / num_chunks);
var remainder = txt.length % num_chunks;

for (var i = 0; i < num_chunks; i++)
{
    chunks[i] = quotient;

    if (i >= (num_chunks - remainder)) chunks[i]++;
}

for (var i = 0; i < txt.length; i += chunks[chunk_count++])
{
    // The substr method would be eaiser, but WebTV can't handle substr.
    // str.substr(i, j) is same as str.substring(i, i + j)
    htm += two_color_fade(txt.substring(i, i + chunks[chunk_count]), colors[color_count], colors[color_count + 1]);

    color_count++;
}

return htm;
}

function fade(frm)
{
var col_list = '';

var txt = frm.intxt.value;

// preset or custom color scheme?
    col_list = frm.selPresets.options[frm.selPresets.selectedIndex].value;

if (txt.length == 0)
{
    alert('You need to enter some text.');
    frm.intxt.focus();
    return;
}


frm.outtxt.value += multi_color_fade(txt, col_list);
}


function rgb_to_hex(r, g, b)
{
// r, g, and b are numbers, not strings

// correct function returns 255 if n > 255 and 0 if n < 0

// The "correct" function doesn't really need to be called, since
// rgb_to_hex will take care of anything < 256 or > -1, but just
// to be on the safe (WebTV) side...
r = correct(r);
g = correct(g);
b = correct(b);

var h = ((r << 16) | (g << 8) | (b)).toString(16);

while (h.length < 6) h = '0' + h;

return '#' + h;
}

function correct(n){if(n>255)return 255;if(n<0)return 0;return n}

// -->
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:15:09+00:00Added an answer on June 4, 2026 at 10:15 pm

    I guess:

    frm.outtxt.value += multi_color_fade(txt, col_list);
    

    should be:

    frm.outtxt.value = multi_color_fade(txt, col_list);
    

    you want to change the value, rather than append to it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why isn't this working? ---HTML-------- <html> <head> <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js></script> <script type=text/javascript src=j.js></script> </head>
I am try to write inside html document. this is my javascript code: <script
<html> <head> <script type=text/javascript> function show_confirm(){ var r=confirm(Hello or Goodbye?); if (r==true){ alert(Hello); window.location.replace(http://www.google.com/);
Hello all I am working in javascript and html5.I want to ask that how
Hello I have this list that i am working on. When i move the
I am new to coffee scripting..This is my first script and is not working..
I am working on extracting text out of html documents and storing in database.
I'm using PHP, HTML & jQuery. Lets say this is my original working index.html
i have this main page index.html <script> $(document).ready(function(){ $(#content).load('page.html'); $(#menu).click(function () { alert('Hello'); });
Hello there i got some code here; <script type=text/javascript> $(function(){ var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/8BCDD04DE8F771B2?v=2&alt=json&callback=?';

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.