50
rated 0 times
[
57]
[
7]
/ answers: 1 / hits: 17366
/ 7 Years ago, fri, february 24, 2017, 12:00:00
In view_candidates
form in my application, I have a button with text REQUEST CONTACT INFO
. When I click on the button, the text will be changed automatically to FINISH
.
Now what happens: When I refresh the page the button text automatically changes to REQUEST CONTACT INFO
.
To overcome this, I gave a status
column in my database.
What I want:
Once user click on the button, the status
should change from 0 to 1.
With status
, I want to display my button text like: if status=0 button should be REQUEST CONTACT INFO
, else it should be FINISH
.
Button code:
<td>
<button type=button id=button class=btn btn-info onclick=getConfirmation(id);>
<b>REQUEST CONTACT INFO</b>
</button>
</td>
SCRIPT:
<script>
function getConfirmation(id)
{
var retVal = confirm(your request is confiremed ?);
if(retVal)
{
$('#button').text('Finish');
$.ajax({
url: Candidate/user_view_candidates/change_status,
type: post,
data: id,
success: function (response)
{
//location.reload();
alert('success');
}
});
}
}
</script>
Controller code:
public function change_status()
{
$id = $this->input->post('candidate_id');
$status = $this->db->query(select status from candidates_details where id = candidate_id)->row()->status;
if($status==0)
{
$status = 1;
}
else
{
$status = 0;
}
$data=array('status'=>$status);
$this->db->where('candidate_id',$id);
$this->db->update('candidates_details',$data);
}
Can someone help me?
Thanks in advance.
More From » jquery