ThemeForest

Change Event

228 posts
  • Sold between 5 000 and 10 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 100 and 199 users
  • Bought between 10 and 49 items
  • Microlancer Beta Tester
  • Has been a member for 2-3 years
  • Exclusive Author
  • Portugal
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

1663 posts
  • Sold between 50 000 and 100 000 dollars
  • Author had a Free File of the Month
  • Bought between 1 and 9 items
  • Exclusive Author
  • Europe
  • Has been a member for 3-4 years
  • Referred between 10 and 49 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
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.

228 posts
  • Sold between 5 000 and 10 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 100 and 199 users
  • Bought between 10 and 49 items
  • Microlancer Beta Tester
  • Has been a member for 2-3 years
  • Exclusive Author
  • Portugal
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.

1663 posts
  • Sold between 50 000 and 100 000 dollars
  • Author had a Free File of the Month
  • Bought between 1 and 9 items
  • Exclusive Author
  • Europe
  • Has been a member for 3-4 years
  • Referred between 10 and 49 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
Tean says

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

228 posts
  • Sold between 5 000 and 10 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 100 and 199 users
  • Bought between 10 and 49 items
  • Microlancer Beta Tester
  • Has been a member for 2-3 years
  • Exclusive Author
  • Portugal
vtimbuc says

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

by
by
by
by
by