javascript - Html multipe input type color ,inserting the selected colors to database -
i using input type color select color customize site. inserting selected color database , retrieve , apply site working nice single input type color. have input type color , button when select color , click button , area name , color inserted database area name = footer , color = #ccc, problem want content,header,left sidebar , right sidebar. can use multiple button multiple input type, seem not professional ,i want multiple input type color , 1 button all. appreciated. in advance.
/**the working code single input type color button***/ choose colour: <input class="color" name="color1" id="color1" placeholder="click choose colour"> <input type="submit" onclick="changebodycolour('color1')" value="apply" /> /**my function insert value database table**/ function changebodycolour(c1) { var selectedcolur = document.getelementbyid(c1).value; //alert(selectedcolur); $("#color1").empty(); $("#loginscreen").empty(); $.ajax({ url: ""+pat+"changecolour.php?ipp="+encodeuricomponent(selectedcolur), type: 'post', beforesend: function() { $('body').css({ opacity: 0.5 }); $("#loading_img").show(); }, success: function(data) { $("#loading_img").hide(); $("#loginscreen").fadein('slow').append(data).delay(1300).fadeout('slow'); $('body').css({ opacity: 2 }); } });//end ajax call } /**and php code**/ $sql = "insert gr_colours values('','".$_get['ipp']."','body')"; $db->insert($sql);
<?php /* try code color.php */ ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>document</title> </head> <body> <div> footer:<br> <input type="color" name="footer" class="color" > <br><br> header:<br> <input type="color" name="header" class="color" > <br><br> aside:<br> <input type="color" name="aside" class="color" > <br><br> <button id="submit">submit</button> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> jquery(document).ready(function($) { $('#submit').click(function(){ var obj={}; $('.color').each(function(e){ obj[$(this).attr('name')]=$(this).val(); }); $.ajax({ url: 'changecolor.php', type: 'post', // datatype: 'json', data: obj, }) .done(function(data) { console.log(data); }) .fail(function() { console.log("error"); }) .always(function() { console.log("complete"); }); }); }); </script> </body> </html> <?php /* changecolor.php */ ?> <?php if(isset($_post)){ $key=array_keys($_post); $value=array_values($_post); $fields="`".implode("`,`", $key)."`"; $values="'".implode("','", $value)."'"; $sql="insert `table_name` ({$fields}) values ({$values})"; echo $sql; } ?>
Comments
Post a Comment