Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/03/2018, 10:59
eurodoblon
 
Fecha de Ingreso: enero-2008
Mensajes: 303
Antigüedad: 17 años, 1 mes
Puntos: 0
Respuesta: llamar funcion js desde php

Gracias Morti:
Pongo el código completo



Código HTML:
<script src="https://code.jquery.com/jquery-1.12.3.min.js" ></script>
<link href="../estilos/estilos_admin.css" rel="stylesheet" type="text/css" />

<script>
function remove(id) {
$(id).remove();
}
							

function newInput(id, nombre, gasto)
	
	{
		var inpt = document.createElement('input');
		inpt.type="text";
		inpt.name=nombre+'['+id+']';
		inpt.id=nombre+'['+id+']';
		inpt.size=6;
		 inpt.setAttribute("class", "gasto");
		inpt.value=gasto;
		document.getElementById('tr'+id).append(inpt);
		
	
	}
$(document).on('ready', function() {
			$('#aceptar').on('click', function(e) {
			window.location.href="sube-excel.php?borrar=banco.xls";
	

			})
		})
</script>
<style>
body{
	margin:0;
	background-color: #333333;
	
}

.remove{
	cursor:pointer;
	padding-left:20px;
}
.tr{
	background-color:#0E21D1;
	color:#FFF;
	text-align:center;
	
	}
.resultados{
font:normal 10pt Verdana;
color:#000;
position:absolute;
top:180px; 
left:400px;
 background-color:#5EC6C0;
  width: 400px;
  padding: 20px;
 -moz-border-radius: 1em;
  -webkit-border-radius: 1em;
  border-radius: 1em;  
 -webkit-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);

}	
</style> 
Código PHP:
<?php 
 
require_once('../Connections/alquiler.php');
  require_once(
'../librerias/excel/reader.php');

  
mysql_select_db($database_alquiler$alquiler);
  
$depart=mysql_query("SELECT alias from casas order by alias ASC" );
 while (
$casas2mysql_fetch_assoc($depart)){ 
     
      
$casas.= ' <option value="'$casas2['alias'].'">'.$casas2['alias'].'</option> ';     
       
      }  
  
$casas.=   '</select>';
  
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read('archivos/banco.xls');


//NUMERO DE COLUMNAS        
$columnas=4;
//NUMNEERO DE FILA QEN QUE COMENZAMOS
$filas=7;

function 
numero($valor){    
if     (
is_numeric($valor)and $valor <0)
$valor=round($valor*-1);
if     (
is_numeric($valor))$valor=round($valor);
return 
$valor;
}
function 
palabras ($texto){
$find = array('PayPal''TPV''REMESA''COMISIONES');
foreach(
$find as $v){
    if(
strpos($texto$v) !== false){
       return 
true;
        break;
    }
}

}

function 
gastos ($texto){
$find = array('PROP''DIANA',  'ENDESA''TRANSFERENCIA''TELEFONOS''TECEM''BOOKING','INGRESO','AGUA','Booking' );
foreach(
$find as $v){
    if(
strpos($texto$v) !== false){
        if((
$v=='PROP') or ($v=='DIANA')  or ($v=='TELEFONOS')or ($v=='AGUA'))$gasto="comunidad";
        if(
$v=='ENDESA')$gasto="energia";
        if(
$v=='TRANSFERENCIA')$gasto="caja";
        if(
$v=='TECEM')$gasto="aplazado";
        if((
$v=='BOOKING') or ($v=='Booking') )$gasto="comisiones";
        if(
$v=='INGRESO')$gasto="caja";

       return 
$gasto;
        break;
    }
}

}
function 
alias ($texto){
    
$findme=array('DIANA''MAITE',  'SAN FELIPE''SAN RAFAEL''VERACRUZ' );
foreach(
$findme as $v){
$pos strpos($texto$v);
if (
$pos !== false) {
    

    
$alias"<option value='$v' selected='selected'>$v</option>";
    return 
$alias;
        break;     
}

}
}



function 
fecha ($valor)
{
    
$timer explode(" ",$valor);
    
$fecha explode("/",$timer[0]);
    
$fechex $fecha[2]."-".$fecha[1]."-".$fecha[0];
    return 
$fechex;
}



if ((isset(
$_POST["envio_cambia"])) && ($_POST["envio_cambia"] == "cambia")) { 
echo 
"<div  id='confirma' class='resultados' ><br/> ".$_POST['rechazos']."<br /> <br /> <p class='aceptar' id='aceptar' > ACEPTAR</p></div></div> ";} 

 
?>
</head>

<body>
<table width="80%" align="center">
  <tr>
    <td align="center"> 
         <img src="../image/benalquiler.jpg" width="148" height="71" />
   </td>
    <td> <p class="azuloscbold" > INGRESAR GASTOS BANCARIOS DE &nbsp; &nbsp; &nbsp; B E N A L Q U I L E R </p></td>
  </tr>
  <tr>
   <td colspan="2"> <hr  width="100%" size="1" noshade="noshade" color="FF9900" /> </td>
  </tr>
</table>
<div style="width:800px; margin-left:20%;"><div id='respuesta'></div>
  
  <?php echo'<form name="f2"id="f2"  method="post" action="procesa-ingresos.php" class="celda02"><table><tr><td></td><td></td><td>
<input type="button" "
 value="Salir"  onclick="window.location=\'../ventas/administrarventas.php\'" /></td>
            <td><input type="submit" name="excel" id="envio" value="Enviar" /></td></tr>'
;
for (
$i $filas$i <= $data->sheets[0]['numRows']; $i++) {

    echo(
"<tr id ='tr".$i."' >");
    for (
$j 1$j <= $columnas$j++) {
        
$dato=$data->sheets[0]['cells'][$i][$j];$ancho=iconv_strlen ($dato);if ($ancho>10){$ancho=40;} else {$ancho=9;}
        
        
        if( 
$j==1){$dato=fecha($dato);$name="fecha[$i]";$id="fecha[$i]";}
        elseif( 
$j==2){$name="concepto[$i]";$id="concepto[$i]";$gasto=gastos($dato);$alias2=alias($dato);if ($alias2!=""){
$alias=$alias2;}else{  $alias"<option value='' selected='selected'>Apartamento</option>";
}    }            
        elseif( 
$j==4){$name="importe[$i]";$id="importe[$i]";}
        elseif( 
$j==5){$name="alias[$i]";$id="alias[$i]";}

        if(
palabras ($dato)and $j==2) {?> <script>remove('#tr<?php echo $i?>');</script><?php }
        if(!
palabras ($dato)and $j==2) {?><script>newInput('<?php echo $i?>','columna','<?php echo $gasto?>');</script><?php }
if (
$j!==3)    echo("<td><input size='".$ancho."'id ='".$id."' name ='".$name."'type='text' value='".numero($dato)."' /></td>");
    }
    echo
"<td>    <select name='alias[$i]' id='alias[$i]' class='alias' style='width: 90px;'>".$alias.$casas."     </td>         
         <td  id ='"
.$i."'class='remove' onClick='remove(\"#tr".$i."\"); return false;'> <img src='../images/delete.png' /></td>
         <td> <input type='hidden'  name='seleccion[$i]'  value='inserta' />  </td>
         </tr>"
;
    
$alias="";
}
            echo
'</table></form>';
?>
  
  
  
</div>
[/PHP]