Welcome Guest, Not a member yet? Register   Sign In
Checkbox event to update text / database field
#1

[eluser]Unknown[/eluser]
Hi all, I am just getting started with CI and am trying to create a customized online run-log for daily tasks. I need a way to populate an HTML text field value to the current time when the checkbox associated with that row is clicked. Additionally, I would like for that value to then be updated (stored) to the corresponding Time field in my database. Any ideas would be appreciated. Here is my code:

VIEW: dctasks_view.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;title&gt;Tasks&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;


<table bgcolor=62A9FF border=3 width=95% cellpadding=3 cellspacing=10>
<tr>
<th><BR><H1>TASKS</H1></th>
</tr>
</table>
<table bgcolor=BBDAFF border=1 width=95% cellpadding=3 cellspacing=5>
<tr>
<th></th>
<th>Time</th>
<th>TaskName</th>
</tr>

<tr>
&lt;?php foreach($query as $row):?&gt;
<td>&lt;input type="checkbox" name="&lt;?echo $row-&gt;ID;?&gt;"></td>
<td>&lt;input type="text" size=6 name="Time_&lt;?echo $row-&gt;ID;?&gt;" value="&lt;?echo $row->Time;?&gt;"></td>
<td>&lt;?echo $row->TaskName;?&gt;</td>
</tr>
&lt;?php endforeach; ?&gt;
</table>

&lt;/body&gt;
&lt;/html&gt;


MODEL: dctasks_model.php

&lt;?php

class dctasks_model extends CI_Model {
function getData() {
$query=$this->db->query('SELECT * FROM tasks');
return $query->result();
}
}
?&gt;


CONTROLLER: dctasks.php

&lt;?php

class Dctasks extends CI_Controller {
function index() {
$this->load->model('dctasks_model');
$data['query'] = $this->dctasks_model->getData();
$this->load->view("dctasks_view", $data);
}
}
?&gt;
#2

[eluser]theprodigy[/eluser]
Quote:Hi all, I am just getting started with CI and am trying to create a customized online run-log for daily tasks. I need a way to populate an HTML text field value to the current time when the checkbox associated with that row is clicked. Additionally, I would like for that value to then be updated (stored) to the corresponding Time field in my database. Any ideas would be appreciated.
First off, welcome to CodeIgniter!
Please remember when posting code, to surround it with the code tags. It makes it much easier to read ;-)

As for your problem, it sounds like you're looking for a javascript/ajax solution. This could easily be done using jQuery. jQuery makes it really easy to bind events (such as click events) and to make ajax calls to your server to save the data into the database.

Take a look at their docs page.
#3

[eluser]Unknown[/eluser]
Quote:Please remember when posting code, to surround it with the code tags. It makes it much easier to read ;-)

Sorry about that, I'll definitely try to do a better job in the future. :-)

Quote:As for your problem, it sounds like you're looking for a javascript/ajax solution. This could easily be done using jQuery. jQuery makes it really easy to bind events (such as click events) and to make ajax calls to your server to save the data into the database.

Take a look at their docs page.

Thank you for pointing me in the right direction... very much appreciated!




Theme © iAndrew 2016 - Forum software by © MyBB