P.S I am not very good in javascript and I know this question has been asked but the solutions does not apply to my problem so I will ask this question again.
I'm stuck with this problem and haven't find the solution yet. I wanted to clear all the things that happened into my modal after its close.
My modal is a form modal, so whenever I click submit, codeigniter validation messages will show by the use of ajax on <div style=font-size:10px;width:50%; id=info></div>
. Now whenever I close the modal, the validation messages stays when I re-open it. What should be done in order to clear those out after closing the modal?
This is the function called by the ajax:
public function addcomp () {
$this->load->library('form_validation');
$this->load->helper('security');
$this->form_validation->set_rules('comp_name','Computer Name','trim|required|callback_pc_exist');
$this->form_validation->set_rules('status','Status','trim|required');
$this->form_validation->set_rules('location','Location','trim|required');
if ($this->form_validation->run()) {
$this->load->model('asset_model');
$result=$this->asset_model->addpc();
if (!$result) {
echo mysqli_error($result);
} else {
echo <div class='alert alert-success alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
Computer Successfully Added!</div>;
}
}
echo validation_errors(<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>,</div>);
}
This is the ajax called by submission:
$(document).ready(function(){
$(#addpc).submit(function(){
var formdata=$(#addpc).serialize();
$.ajax({
url:asset_management/addcomp,
type:POST,
data: formdata,
async: true,
}).done(function( formdata ) {
$('#info').html(formdata);
$(#addpc)[0].reset();
viewdata();
});
return false;
});
});