I am working in codeigniter. I have created one table and its html is like this:
<table>
<tr>
<td>
<center><label style="font-weight:normal" class="t_date"><?php echo date('Y-m-d'); ?></label></center>
</td>
<td>
<center><label style="font-weight:normal" class="b_id"><?php echo $result[0]->branch_id; ?></label></center>
</td>
</tr>
<tr>
<td></td>
<td><input type="button" onClick="window.print();" value="Print" name="print" id="print"/></td>
</tr>
</table>
Now I want to get the value of td so I have written jQuery like this:
<script>
jQuery(document).ready(function(){
jQuery("#print").click(function(){
//alert(123);
var to_date = jQuery(".t_date").text();
var to_date = jQuery(".b_id").text();
});
});
</script>
And I got value of it. Now i want to insert these all value into database so what code should i have to write?
jQuery(document).ready(function () {
jQuery("#print").click(function () {
alert(123);
var to_date = jQuery(".t_date").text();
var to_id = jQuery(".b_id").text();
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>index.php/controller/function",
data: {to_date: to_date, to_id: to_id},
success: function (html) //we're calling the response json array 'permissions'
{
// action
}
});
});
});
this ajax will call your function in controller.. in your function call a model function to insert the values to db.
Refer - AJAX
<script>
jQuery(document).ready(function () {
jQuery("#print").click(function () {
$.ajax({
url: '/path/to/file',
type: 'default GET (Other values: POST)',
dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
data: {
t_date: jQuery(".t_date").text(),
b_id: jQuery(".b_id").text(),
},
success: function (response) {
alert(response);
}
});
});
});
</script>
this will do the work
you can do so using AJAX.
Create a webpage to accept inputs as parameters and save them into database. And study this link: http://www.w3schools.com/jquery/jquery_ajax_get_post.asp
code to do so:
$.get("web page address with parameters ", function(data, status){
alert("Data: " + data + "
Status: " + status);
});
For example: if you created a webpage named "savedata.php" that takes inputs as parameters and saves into database.
Then
$.get("[root_path]/savedata.php?[paramaters]", function(data, status){
alert("Data: " + data + "
Status: " + status);
});
[root_path] is the root path of you webpage and [parameters] is "&" separated parameters.