Ok guys thanks for your sollicitude.
well, I have a template derived from the comon one in the distribution: here is the code where i added my jquery code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<?php
foreach($css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
<script type="text/javascript">
$(document).ready(function() {
//$('#etatpayement_field_box').hide();
$('#idtype_field_box').append('<div id="champstype" style="border: 1px solid #000;"> Selectionez un type de facture</div>');
$('#idtype_field_box').change(function(){
var typef;
typef = $('#field-idtype').val();
if (typef == ""){
$('#champstype').html('Selectionez un type de facture');
}else{
$.ajax({
'url' : 'creances/champsupp',
'type': 'POST',
//'dataType': 'json',
'data': {'idtype':typef},
'success': function(response){
// okay, here you need to write a script to change the DOM, but for now I'll just show it in javascript console
//console.log(response);
$('#champstype').html(response);
}
});
//$('#champstype').html(typef);
}
});
$('#idclient_input_box').append('<a href="<?php echo site_url()?>/creances/quick_add/" class="various fancybox.ajax">Ajouter</a>');
});
</script>
<style type='text/css'>
body
{
font-family: Arial;
font-size: 14px;
}
a {
color: blue;
text-decoration: none;
font-size: 14px;
}
a:hover
{
text-decoration: underline;
}
</style>
</head>
<body>
<div style='height:20px;'></div>
<div>
<?php echo $output; ?>
</div>
</body>
</html>
The in y controller I have two methods where I want to load two different views.
function _creance_output($output = null)
{
$this->load->view('creance.php',$output);
}
function factures()
{
$crud = new grocery_CRUD();
$crud->set_table('factures');
$crud->set_subject('Factures');
$crud->set_relation('idtype', 'types', 'designation');
$crud->field_type('etatpayement','enum',array('En cours','En retard', 'Recl&eacturee'));
$crud->set_relation('idclient', 'clients', 'designation');
$crud->field_type('active','enum',array('yes','no'));
$output = $crud->render();
$this->_creance_output($output);
}
when adding an item here, there is a field where the previous:
$('#idtype_field_box').change(function(){
i addes tothe view applies. I mean when the select box changes it is supposed to make an ajax request within the:
'url' : 'creances/champsupp',
here is that method:
function champsupp()
{
$this->data['typefact'] = $_POST['idtype'];
$this->load->view('creance2.php', $this->data);
}
At this stage it didn't work! but with the victor's suggestion i changed the path atthe ajax query like this
'url' : '<?php echo site_url()?>/creances/champsupp',
And it finally works, hope it will help.
Thank you guys!