Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
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

 Answers
19

Check this:



View



<input type=hidden name=candidate_id value=<?php echo $candidate_id; ?>/>//your candidate_id
<button type=button id=button class=btn btn-info >
<b><?php $status == 0? 'REQUEST CONTACT INFO':'FINISHED';?></b>//your status value
</button>

<script src=<?php echo base_url(); ?>assets/plugins/jquery.min.js></script>


js



$('#button').click(function() {
var candidate_id = $('input[name=candidate_id]').val();
var url = 'your_cntroller_name/change_status/';
$.ajax({
url: your_base_url + url,
type: 'POST',
data: {'$candidate_id': $candidate_id},
dataType: 'JSON',
success: function(data) {
$('#button').text('FINISHED');
}
});
});


Controller



public function change_status() {
$candidate_id = $this->input->post('candidate_id');
$this->your_model->update_status($candidate_id);

echo true;
exit;
}


Model



public function update_status($candidate_id) {

//your query toupdate status

}

[#58793] Wednesday, February 22, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stephonkeandrer

Total Points: 392
Total Questions: 94
Total Answers: 100

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
;