Reputation: 13248
I'm using this colorpicker http://www.eyecon.ro/colorpicker and am trying to capture the hex value so that I can use it on the server side to store the selected color.
I'm unable to get the selected color after changing the default color.
Here is my code:
var currentHex = '#0000ff';
alert(currentHex);
$('#colorSelector').ColorPicker({
color: currentHex,
onShow: function (colpkr) {
$(colpkr).fadeIn(500);
return false;
},
onHide: function (colpkr) {
$(colpkr).fadeOut(500);
return false;
},
onChange: function (hsb, hex, rgb) {
// every time a new colour is selected, this function is called
currentHex = hex;
$('#mycolor').val = currentHex;
}
});
Html:
<div id="colorSelector"><div style="background-color: rgb(62, 62, 189); "></div></div>
<input type="text" maxlength="6" size="6" id="mycolor" value="00ff00">
Here is my Demo
Upvotes: 3
Views: 6349
Reputation: 33153
$(document).ready(function() {
var currentHex = '#0000ff';
$('#colorSelector').ColorPicker({
color: currentHex,
onShow: function(colpkr) {
$(colpkr).fadeIn(500);
return false;
},
onHide: function(colpkr) {
$(colpkr).fadeOut(500);
return false;
},
onChange: function(hsb, hex, rgb) {
$('#colorSelector div').css('backgroundColor', '#' + hex);
alert(hex);
$('#mycolor').val(currentHex);
}
});
});
Upvotes: 1
Reputation: 13421
$('#mycolor').val = currentHex; //wrong syntax
should be
$('#mycolor').val(currentHex);
Upvotes: 5