How to change the status on modal confirm alert ok button in codeignter?
How to change the status on modal confirm alert ok button in codeignter?
I have setup modal alert to change status but status become changed automatically when open modal alert only. I need to change the status only when click on ok
button of modal, can anyone help me?
ok
My controller
public function Changetobilledstatus()
$id=$this->input->post('value');
$data=array('Rental_status'=>3);
$this->General_model->update($this->table,$data,'RA_id',$id);
echo json_encode($data);
My html
<div id="UnbilledModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Do You Need update status into billed ?</h4></div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary option">OK</button>
</div>
</div>
</div>
</div>
My script
$('td', row).eq(10).html('<center><select id="Rental_status" onchange="changeStatus('+data['RA_id']+')"><option value="1">Select</option><option value="2">Billed</option></select></center>');
function changeStatus(RA_id)
var val=$("#Rental_status").val();
var id= RA_id;
if(RA_id)
$.ajax(
url:"<?php echo base_url()?>index.php/Rental_agreement/Changetobilledstatus",
type: 'POST',
data: value:RA_id,
dataType: 'json',
success:
function(data)//quotation_status
//location.reload();
//alert(data['quantity']);
$('#UnbilledModal').modal();
,
error:function(e)
console.log("error");
);
I need to update rental status field into 3 only when click on modal ok button
– Shereefva
Sep 15 '18 at 4:01
Ok, but then why use a select box? If you are going to have 1 option which is "billed" why make the user select from a dropdown? Just have the modal open on click. If user hits ok then it changes the status. Simpler, and better ux.
– Alex
Sep 15 '18 at 4:07
1 Answer
1
=> your HTML CODE
$('td', row).eq(10).html('<center><select id="Rental_status" onchange="changeStatus('+data['RA_id']+')"><option value="1">Select</option><option value="2">Billed</option></select></center>');
// in select you have to write code in this manner
'<a title="Change Status" class="btn btn-danger btn-xs" data-user="' + id + '" data-status="' + data + '" href="#UnbilledModal" data-toggle="modal" onclick="change_status(this)">Disable</a>'
<div id="UnbilledModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<?php echo form_open('your url', array('class' => 'form-horizontal', 'name' => 'your form name')); ?>
<input type="hidden" name="id" /> //fetch id and status
<input type="hidden" name="status" />
<h4 class="modal-title">Do You Need update status into billed ?</h4></div>
<div class="pull-right">
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
<button type="submit" class="btn btn-success">Yes</button>
</div>
<?php echo form_close(); ?>
<div class="modal-footer">
<button type="submit" class="btn btn-primary option">OK</button>
</div>
</div>
</div>
</div>
=> your Javascript Code
function change_status(obj)
var id = $(obj).data('id');
var status = $(obj).data('status'); // here you can fetch data value
$('input[name="id"]').val(id);
$('input[name="status"]').val(status);// use in modal right
function show_modal(obj)
var modal_id = $(obj).attr('href');
var content = $(modal_id).children('div.modal-dialog').children('div.modal-content');
var data_url = $(obj).attr('data-url');
$.ajax(
url: data_url,
dataType: "html",
catch : false,
success: function (data)
$(content).html(data);
);
how is "show_modal" called? don't see any reference to it
– Alex
Sep 15 '18 at 4:11
this is just reference my friend. You can use only change_status function my ref <a></a> link and modal thats it
– Rushi Shukla
Sep 15 '18 at 4:29
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What status? What is changed automatically?
– Alex
Sep 15 '18 at 3:26