Welcome Guest, Not a member yet? Register   Sign In
Code Igniter + PHP + Javascript
#1

[eluser]Mareli[/eluser]
Hi everyone! I'm working on a proyect using code igniter+php+javascript, well, I have an array of checkbox and 2 buttons (b1, b2), and when I activate one check box, b1 must be able and b2 disabled; if I unchecked a checkbox, if there's no other checkbox activate, b1 must be disabled and b2 able. This part works great just with the first checkbox, but later, it's work anymore.

This is the function where I declare the checkboxs.
Code:
{
            $dat = array(
            'name'            => 'cbox['.$objdetalle->iddetallepedido.']',
            'id'            => 'cbox',
            'value'            => $objdetalle->iddetallepedido,
            'checked'        => FALSE,
            'onClick'        => 'valida('.$idOrdenCompra.','.$objdetalle->iddetallepedido.');',
            );
            $this->table->add_row(array(
                form_checkBox($dat),
                $this->model->getNombreMaterial($objdetalle->iddetallepedido),
                '',
                $objdetalle->cantidad,
                dinero_format($objdetalle->precioproveedor),
                dinero_format($objdetalle->cantidad * $objdetalle->precioproveedor)
            ));    
   }

And this is where I declare the rest of the buttons.

Code:
private function makeFootButtons($idOrdenCompra) {
        $data = array(
        'name'=> 'recepcion['.$idOrdenCompra.']','id'=> 'recepcion['.$idOrdenCompra.']','value'=> 'Recepcion',
        'class'=> 'formbutton','style'=> 'margin-left:10px', 'onClick'=>'xajax_setConfirmacion(xajax.getFormValues(\'confirmacion'.$idOrdenCompra.'\'),'.$idOrdenCompra.')'        
        );
        $out   = '<div>&lt;form id="confirmacion'.$idOrdenCompra.'" name="confirmacion'.$idOrdenCompra.'"&gt;';
        if($this->model->checkPermisoConfirmacionAlmacen($this->db_session->userdata('idRol')) && !$this->model->isConfirmadoAlmacen($idOrdenCompra))
            $out  .= 'Confirmacion Almacen: '.form_checkbox('almacen','1','','id="almacen"');
        else
            $out  .= 'Confirmacion Almacen: '.form_checkbox('almacen','1',$this->model->isConfirmadoAlmacen($idOrdenCompra),'id="almacen" disabled="disabled"');
            
        if($this->model->checkPermisoConfirmacionResidente($this->db_session->userdata('idRol')) && !$this->model->isConfirmadoResidente($idOrdenCompra))
            $out  .= 'Confirmacion Residente: '.form_checkbox('residente','1','','id="residente"');
        else
            $out  .= 'Confirmacion Residente: '.form_checkbox('residente','1',$this->model->isConfirmadoResidente($idOrdenCompra),'id="residente" disabled="disabled"');
            
        if($this->model->isConfirmadoAlmacen($idOrdenCompra) && $this->model->isConfirmadoResidente($idOrdenCompra))
            $out  .= form_button('ticket'.$idOrdenCompra,'ticket','id ="ticket'.$idOrdenCompra.'"class="formbutton" style="margin-left:10px" onclick="xajax_getTicket('.$idOrdenCompra.')"');
        else
            $out  .= form_button($data);
        $out  .= '<tr><td></td><td>&lt;input name="generar['.$idOrdenCompra.']" type="button" class="formbutton" id="generar['.$idOrdenCompra.']" value="Agregar a Stock" disabled="disabled"&gt;&lt;/td><td></td>';
        $out  .= '&lt;/form&gt;&lt;/div>';
        $out  .= '<div id="ticketPanel'.$idOrdenCompra.'" class="ticket">&nbsp;</div>';
        return $out;
    }

This is the javascript function in the view.

Code:
function valida(r,t){
var checkboxes = document.getElementById("forma").cbox;
var cont = 0;
    for (var x=0; x < checkboxes.length; x++) {
        if (checkboxes[x].checked) {
            cont = cont + 1;
        }
    }
    
    if (cont == 0){
    //alert('Contador cero');
    document.getElementById("recepcion["+r+"]").disabled = false;
    document.getElementById("generar["+r+"]").disabled = true;
    }
    else{
    //alert('contador = ' +cont);
    document.getElementById("recepcion["+r+"]").disabled = true;
    document.getElementById("generar["+r+"]").disabled = false;
    }
}
#2

[eluser]slowgary[/eluser]
what doesn't work? Give more details. Can you post a link to this working (or no working)?




Theme © iAndrew 2016 - Forum software by © MyBB