Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
110
rated 0 times [  117] [ 7]  / answers: 1 / hits: 16198  / 9 Years ago, wed, july 29, 2015, 12:00:00

I am using bootstrap colorpicker but my requirement is to change the default onload color differently on change of select drop down list.



I am using the below constructor :-



$('#colorPicker').colorpicker();


This is the code in jsp.



<div id='colorPicker'>
<input type='text' value='#ea0437' class='form-control'/>
<span class='input-group-addon'></span>
</div>


I am getting the color code from database so I can't add the initial color code as given above in the following line :



<input type='text' value='#ea0437' class='form-control'/>


How can I provide this color in constructor ?
The documentation says that there is a color option, but no demonstration given. How can I provide the color initially ? Something like this :



$('#colorPicker').colorpicker({
color : '#ea0437'
})


Any suggestion? Thanks in advance.


More From » jquery

 Answers
313

I got mine to work after days of trying it out. It appears an onchange event has been attached to the colorpicker input field, but doesn't get fired, after setting the value through script. Hence u have to fire it manually, like this :



$(#inputcolor).val(#bbccff);
$(#inputcolor).trigger('change');

[#65627] Monday, July 27, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marinal

Total Points: 655
Total Questions: 99
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;