- I am trying to update the value in a textbox using a script and then save it in my database through my controller. Although the value in the textbox changes, the ajax call does not work as expected. I apologize for any mistakes, as I am still new to this process.
//script
$(document).ready(function() {
$('#colorselector_1').colorselector({
callback : function(value,color) {
var colorit = $("#colorColor").val(color);
$.ajax({
type: 'POST',
url: '/addItemColor',
data: {'color':colorit},
});
}
});
});
//controller
public function addItemColor(){
$color = Input::get("color");
$cake= cakeModel::find($_SESSION['cakeModelID']);
$cake->colorlayer1=$color;
$cake->save();
return Redirect::to('home'); //temporary
}
//html
<section id="colorselectors">
<select id="colorselector_1" >
<option value="1" data-color="#A0522D">sienna</option>
<option value="47" data-color="#CD5C5C" selected="selected">indianred</option>
<option value="87" data-color="#FF4500">orangered</option>
<option value="17" data-color="#008B8B">darkcyan</option>
<option value="18" data-color="#B8860B">darkgoldenrod</option>
<option value="68" data-color="#32CD32">limegreen</option>
<option value="42" data-color="#FFD700">gold</option>
<option value="77" data-color="#48D1CC">mediumturquoise</option>
<option value="107" data-color="#87CEEB">skyblue</option>
<option value="46" data-color="#FF69B4">hotpink</option>
<option value="47" data-color="#CD5C5C">indianred</option>
<option value="64" data-color="#87CEFA">lightskyblue</option>
<option value="13" data-color="#6495ED">cornflowerblue</option>
<option value="15" data-color="#DC143C">crimson</option>
<option value="24" data-color="#FF8C00">darkorange</option>
<option value="78" data-color="#C71585">mediumvioletred</option>
<option value="123" data-color="#000000">black</option>
</select>
<input class="boxi" type="text" id="colorColor"/>
</section>