Reputation: 61
I'm using a jquery like this http://www.jque.re/plugins/forms-controls/quick.tag/ to create quicktags. The quicktags are stored in a series of div tags like so
<div id="taglist">
<div class="tag">
<a class="close">x</a>
Red
</div>
<div class="tag">
<a class="close">x</a>
Blue
</div>
<div class="tag">
<a class="close">x</a>
Green
</div>
</div>
How will I be able to use the values of "Red" "Blue" and "Green" to insert into database? Sorry I'm new to this. Thanks.
Upvotes: 0
Views: 1182
Reputation: 24001
1- You need to use javascript to get the data from divs you want and you will need server side language like PHP as well
2- While you tagged Jquery I assume you included it in html <head>
or before </body>
3- how can you use jquery?? see next example
$(document).ready(function(){
var arrayofcolors = [];
$('#taglist > .tag').each(function(){
var thisColor = $(this).text().replace('x' , '').trim().toLowerCase();
arrayofcolors.push(thisColor);
});
alert(arrayofcolors);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="taglist">
<div class="tag">
<a class="close">x</a>
Red
</div>
<div class="tag">
<a class="close">x</a>
Blue
</div>
<div class="tag">
<a class="close">x</a>
Green
</div>
</div>
about passing arrayofcolors to php and save it into database you need to use $.ajax()
method .. and use it like
$.ajax(function(){
url : 'to your php url here',
method : 'POST',
data : {arrayofcolors : arrayofcolors},
success : function(data){
// returned data from php file
alert(data);
}
});
in you php file
<?php
echo $_POST['arrayofcolors'];
?>
this steps will return the alert with your colors
Upvotes: 2