/    Sign up×
Community /Pin to ProfileBookmark

Color preview script

Hello!

I wish to make a script that shows the color of a hexadecimal code that have been written into a text input field, like this:

[url]http://yfrog.com/4jscriptsyj[/url]

I really suck at JavaScript, can somone please help me? ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorFeb 23.2010 — Could be something like this (but it depends on how you want to interpret the hexa values when the user enters 1,2,3,4,5,6 characters)
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;style type="text/css"&gt;
#box {
height: 25px;
width: 25px;
border:solid 1px #000;
}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
function showColor(color){
switch(color.length){
case 1:
color=color+color+color;
break;
case 2:
color=color+color+color;
break;
case 3:
var s=color.split('');
color=s[0]+s[0]+s[1]+s[1]+s[2]+s[2];
break;
case 6:
color=color;
break;
default:
return
}
var obj=document.getElementById('box');
obj.style.backgroundColor='#'+color;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=""&gt;
&lt;input type="text" onkeyup="showColor(this.value)" onblur="showColor(this.value)"&gt;
&lt;div id="box"&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;


I really suck at JavaScript
[/quote]

Next time either you learn javascript or you hire someone to do the job. There is no middle way in programming.
×

Success!

Help @Woolwich spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...