333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

Hey guys,

I need your help. I have a colorpicker where the users can select the color and this color is saved on a variable. The problem is that when I change the color the variable is updated but I can’t get the new value. I need an event to check if the variable was changed to update the value.

Here is the code:
$('input').ColorPicker({
    onChange: function (hsb, hex, rgb) {
        var color = hex;
    }
});

$('#teste').text(color);

I’ve tried using live and bind but my jQuery skill is basic.

I hope someone know how to do it.

Thanks

1681 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
Tean says

For the syntax you showed ‘onChange’ is going to fire when color changes so you can call your action from there.

Or maybe you just need to make this color variable global, and define it out of this block of code so you can access it.

333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

I have to keep the code outside of the “onChange” because I need to use this variable on more functions and with more variables combined.

As the variable needs to be in “onChange” event I don’t know how can I make it global.

1681 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
Tean says

I meant declare variable color outside of this scope block, and then inside use this variable.

333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

I’ve started to do it in other way and is working fine, thank you for your help Tean.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by