Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] boton submit y evento

Estas en el tema de boton submit y evento en el foro de PHP en Foros del Web. Buenas tardes: Un formulario con varios input button. Una funcion en javascript que desactiva varios de esos botones. Si uso type=submit con onclick= nombrefuncion(): se ...
  #1 (permalink)  
Antiguo 29/12/2014, 12:58
 
Fecha de Ingreso: noviembre-2005
Mensajes: 146
Antigüedad: 18 años, 5 meses
Puntos: 1
boton submit y evento

Buenas tardes:
Un formulario con varios input button.
Una funcion en javascript que desactiva varios de esos botones.
Si uso type=submit con onclick= nombrefuncion():
se ejecuta la funcion, no se ejecuta el codigo php y se desejecuta la funcion(los botones quedan activados de nuevo).
Si uso type=button el evento onclick ejecuta la función de desactivar los botones, pero no ejecuta el codigo php que cierra la conexión y vacía los campos del formulario.
¿Como puedo ejecutar tanto la función javascript y el codigo php desde el mismo boton.
Gracias.
  #2 (permalink)  
Antiguo 29/12/2014, 14:35
(Desactivado)
 
Fecha de Ingreso: enero-2013
Mensajes: 289
Antigüedad: 11 años, 3 meses
Puntos: 10
Respuesta: boton submit y evento

usa jquery

Código Javascript:
Ver original
  1. $(document).ready(function(){
  2.       $('#mybutton').click(function(){
  3.                 alert('hola');
  4.       });
  5. });
  #3 (permalink)  
Antiguo 29/12/2014, 17:01
 
Fecha de Ingreso: noviembre-2005
Mensajes: 146
Antigüedad: 18 años, 5 meses
Puntos: 1
Respuesta: boton submit y evento

Hola gracias por la respuesta.
No funciona.

Se desencadena el codigo php:
cierra la conexion y vacia los campos del formulario,
Pero el evento de invalidar los botones input no se efectua.

Esta parte del codigo no se ejecuta:

<script type="text/javascript" src="zepto.min.js" src="jquery-2.1.1.js">

$(document).ready(
function(){$('#nuevo').click(function
({
var mivar = document.getElementsByTagName('input');
for(i=0; i< mivar.length; i++)
{
mivar[i].readOnly = false;
}
var mivar = document.getElementsByTagName('select');
for(i=0; i< mivar.length; i++)
{
mivar[i].disabled = false;
}
var mivar = document.getElementsByName('btn1');
for(i=0; i< mivar.length; i++)
{
mivar[i].disabled = true;
}
});
});

El boton que desencadena el codigo php y javascript

<input type="submit" id="nuevo" name="btn1" value="Nuevo" />
  #4 (permalink)  
Antiguo 29/12/2014, 18:23
 
Fecha de Ingreso: septiembre-2013
Mensajes: 125
Antigüedad: 10 años, 7 meses
Puntos: 3
Respuesta: boton submit y evento

Lo que tienes que hacer es ejecutar el js y sino lo tienes activado ejecutar el php ¿Como asin?

Haces un formulario con su php normal.
Código PHP:
Ver original
  1. if(nombre esta vacio)
  2. Echo ''
  3. Else
  4. Echo 'todo correcto'
  5. Fin

Despues tienes que crear los mismos filtros pero con JS y utilizar onclick="".

Si por algun motivo no se ejecuta el js, se ejecuta el php
  #5 (permalink)  
Antiguo 30/12/2014, 07:45
Avatar de jose_php  
Fecha de Ingreso: mayo-2014
Mensajes: 44
Antigüedad: 9 años, 11 meses
Puntos: 2
Respuesta: boton submit y evento

Hola, podrias mostrar todo tu codigo y a que ruta destina por favor, para poder ayudarte, aunque al parecer la mejor salida seria ajax, pero de todas maneras comparte un poco tu codigo.

Saludos.
  #6 (permalink)  
Antiguo 30/12/2014, 10:49
 
Fecha de Ingreso: noviembre-2005
Mensajes: 146
Antigüedad: 18 años, 5 meses
Puntos: 1
Respuesta: boton submit y evento

Divido el código en dos apartados. No sé como incluirlo todo ya que tiene mas de 10.000 caracteres y no permite introducirlos todos en uno solo.

Cita:
<?php
include("conexion.php");
$sqlape="SELECT * FROM clientes";
$resultape=mysql_query($sqlape);

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="Estilo/formulario.css">
<script type="text/javascript">

/*Si el input no tiene fecha agrega la fecha del sistema como fecha del presupuesto*/
function add_fecha()
{
/*Asigno a la variable x el input de la fecha del presupuesto*/
var x = document.getElementById('i1').value;
/*Creo la variable que contendrá la fecha del sistema*/
var D = new Date();
/*Creo las variables para contener dia, mes y hora*/
var d = D.getDate();
var m = D.getMonth();
var y = D.getFullYear();
/*Si el input de fecha_presupuesto está vacio, introduzco la fecha del sistema*/
if(x === ""){i1.value = d +"/" + m + "/" + y }
}
function modificar()
{
var mivar = document.getElementsByTagName('input');
for(i=0; i< mivar.length; i++)
{
mivar[i].readOnly = false;
}
var mivar = document.getElementsByTagName('select');
for(i=0; i< mivar.length; i++)
{
mivar[i].disabled = false;
}
var mivar = document.getElementsByName('btn1');
for(i=0; i< mivar.length; i++)
{
mivar[i].disabled = true;
}
}
function cancelar()
{
var mivar = document.getElementsByTagName('input');
for(i=0; i< mivar.length; i++)
{
mivar[i].readOnly = true;
}
var mivar = document.getElementsByTagName('select');
for(i=0; i< mivar.length; i++)
{
mivar[i].disabled = true;
}
var mivar = document.getElementsByName('btn1');
for(i=0; i< mivar.length; i++)
{
mivar[i].disabled = false;
}
}

</script>
<title> Formulario de registro </title>
</head>
  #7 (permalink)  
Antiguo 30/12/2014, 10:55
 
Fecha de Ingreso: noviembre-2005
Mensajes: 146
Antigüedad: 18 años, 5 meses
Puntos: 1
Respuesta: boton submit y evento

Cita:
<body>
<h1> Formulario de registro </h1>
<?php

$var0=""; //Id del presupuesto
$var1=""; // Fecha presupuesto
$var2=""; // Número de presupuesto
$var3=""; // Apellidos cliente
$var4=""; // Nº de usuarios
$var5=""; // Inicio del evento
$var6=""; // Fin del evento
$var7=""; // Días de duración
$var8=""; // Horas de duración
$var9=""; // Confirmación del depósito
$var10=""; // Fecha confirmación
$var11=""; // Depósito entregado
$var12=0.0; // Presupuesto
$var13=0.0; // Coste servicios
$var14=0.0; // Resultado
$var15=""; // Fecha de la factura
$var16=""; // Nº factura
$var17=""; // Servicios a coordinar
$var18="Este es el texto por defecto"; // Observaciones

$sql="SELECT count(Id_Presupuesto) as totreg FROM presupuestos";
$cs=mysql_query($sql,$cn);

while($resul=mysql_fetch_array($cs))
{
$totreg=$resul[0];
$cont=$totreg;
}

$sql="SELECT * FROM presupuestos";
$cs=mysql_query($sql,$cn);

while($resul=mysql_fetch_array($cs))

{

$var0=$resul[0];
$mifecha= date_create($resul[1]);
$var1=date_format($mifecha,'d/m/Y');
$var2=$resul[2];

$var3=$resul[3];
$misql="SELECT * FROM clientes WHERE id_Clientes = $var3";
$ca=mysql_query($misql,$cn);
while($resul_a=mysql_fetch_array($ca))
{
$var3=$resul_a['1'];
}
$var4=$resul[4];
$mifecha= date_create($resul[5]);
$var5=date_format($mifecha,'d/m/Y');
$mifecha= date_create($resul[6]);
$var6=date_format($mifecha,'d/m/Y');
$var7=$resul[7];
$var8=$resul[8];
$var9=$resul[9];
$mifecha= date_create($resul[10]);
$var10=date_format($mifecha,'d/m/Y');
$var11=$resul[11];
$var12=$resul[12];
$var13=$resul[13];
$var14=$resul[14];
$mifecha= date_create($resul[15]);
$var15=date_format($mifecha,'d/m/Y');
$var16=$resul[16];
$mifecha='';
}

if(isset($_POST["btn1"]))
{
$btn=$_POST["btn1"];
$bus=$_POST["txtbus"];
if($btn=="Buscar")
{

$sql="SELECT *FROM Presupuestos where Id_Presupuesto='$bus'";
$cs=mysql_query($sql,$cn);
while($resul=mysql_fetch_array($cs))
{
$var0=$resul[0];
$var1=$resul[1];
$var2=$resul[2];
$var3=$resul[3];
$var4=$resul[4];
$var5=$resul[5];
$var6=$resul[6];
$var7=$resul[7];
$var8=$resul[8];
$var9=$resul[9];
$var10=$resul[10];
$var11=$resul[11];
$var12=$resul[12];
$var13=$resul[13];
$var14=$resul[14];
$var15=$resul[15];
}
}

//================================================== =================
//INICIO DE METODOS DEDICADOS A LA PAGINACIÓN DEL FORUMULARIO

if($btn=="Primero")
{
$cont=1;
$max_reg=$cont;
include("seleccionar_bd.php");
}

if($btn=="Anterior")
{
$cont=$_POST["txtvariable"];
if($_POST["txtvariable"] >1 )
{
$cont=$cont-1;
$max_reg=$cont;
include("seleccionar_bd.php");
}
elseif ($_POST["txtvariable"] =1)
{
$cont=1;
$max_reg=$cont;
include("seleccionar_bd.php");
}
}
if($btn=="Siguiente")
{
$cont=$_POST["txtvariable"];
if($_POST["txtvariable"]!==0 and $_POST["txtvariable"] < $totreg)
{
$cont=$cont+1;
$max_reg=$cont;
include("seleccionar_bd.php");
}
}
if($btn=="Ultimo")
{
$cont=$totreg;
$max_reg=$cont;
include("seleccionar_bd.php");
}

//FINAL DE METODOS DEDICADOS A LA PAGINACIÓN DEL FORUMULARIO
//================================================== ====================

if($btn=="Nuevo")
{
$cn=mysql_close($cn);
$var0=""; //Id del presupuesto
$var1=""; // Fecha presupuesto
$var2=""; // Número de presupuesto
$var3=""; // Apellidos cliente
$var4=""; // Nº de usuarios
$var5=""; // Inicio del evento
$var6=""; // Fin del evento
$var7=""; // Días de duración
$var8=""; // Horas de duración
$var9=""; // Confirmación del depósito
$var10=""; // Fecha confirmación
$var11=""; // Depósito entregado
$var12=0.0; // Presupuesto
$var13=0.0; // Coste servicios
$var14=0.0; // Resultado
$var15=""; // Fecha de la factura
$var16=""; // Nº factura
$var17=""; // Servicios a coordinar
$var18="Este es el texto por defecto"; // Observaciones<script type="txt/javascript">

}
if($btn=="Agregar")
{
$fpr=$_POST["txtfpr"];
$pre=$_POST["txtpre"];
$ape=$_POST["txtape"];
$usu=$_POST["txtusu"];
$ini=$_POST["txtini"];
$fin=$_POST["txtfin"];
$dep=$_POST["txtdep"];
$fde=$_POST["txtfde"];
$idp=$_POST["txtidp"];
$ser=$_POST["txtser"];
$vpr=$_POST["txtvpr"];
$cos=$_POST["txtcos"];
$res=$_POST["txtres"];
$fac=$_POST["txtfac"];
$ffa=$_POST["txtffa"];
$obs=$_POST["txtobs"];


$sql="INSERT into presupuestos values ('$fpr','$pre','$ape','$usu','$ini','$fin','$dep', '$fde','$idp','$ser','$vpr','$cos','$res','$fac',' $ffa','$obs')";
$cs=mysql_query($sql,$cn);
echo "<script> alert('Se insert&oacute; correctamente');</script>";
}

if($btn=="Actualizar")
{
$fpr=$_POST["txtfpr"];
$pre=$_POST["txtpre"];
$ape=$_POST["txtape"];
$usu=$_POST["txtusu"];
$ini=$_POST["txtini"];
$fin=$_POST["txtfin"];
$dep=$_POST["txtdep"];
$fde=$_POST["txtfde"];
$idp=$_POST["txtidp"];
$ser=$_POST["txtser"];
$vpr=$_POST["txtvpr"];
$cos=$_POST["txtcos"];
$res=$_POST["txtres"];
$fac=$_POST["txtfac"];
$ffa=$_POST["txtffa"];
$obs=$_POST["txtobs"];

$sql="UPDATE presupuestos set fecha_presupuesto='$fpr',Ref_Pres='$pre',Id_Client e='$ape',Usuarios='$usu', Fecha_Inicio ='$ini',
fecha_fin ='$fin',


where Ref_Pres='$pre'";

$cs=mysql_query($sql,$cn);
echo "<script> alert('Se actualizo correctamente');</script>";
}
}

?>
  #8 (permalink)  
Antiguo 30/12/2014, 10:57
 
Fecha de Ingreso: noviembre-2005
Mensajes: 146
Antigüedad: 18 años, 5 meses
Puntos: 1
Respuesta: boton submit y evento

Cita:
<form method="POST" action="">
<table>
<tr>
<td>
Id del presupuesto:
</td>
<td>
<input type="text" class="in" name="txtidp" readonly="readonly" value="<?php echo $var0 ?>";/></td>
</tr>
<tr>
<td>
Fecha del presupuesto:
</td>
<td>
<!--Este input tiene el evento onclick para introducir la fecha del sistema si no tiene valor el campo-->
<input type="date" id="i1" class="in" name="txtfpr" readonly="readonly" value="<?php echo $var1?>" onclick="add_fecha()"/>
</td>
</tr>
<tr>
<td>
Presupuesto número:
</td>
<td>
<input type="text" class="in" name="txtpre" readonly="readonly" value="<?php echo $var2 ?>"/></td>
</tr>
<tr>
<td>
Apellidos:
</td>
<td>
<select type= "" class="tx" disabled= "disabled" name="txtape" value="">
<option value= ""><?php echo $var3 ?></option>
<?php
while ($fila=mysql_fetch_row($resultape))
{
echo "<option value='".$fila['0']."'>".$fila['1']."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>
Nº usuarios:
</td>
<td>
<input type="text" class="in" name="txtusu" readonly="readonly" value="<?php echo $var4 ?>"/>
</td>
</tr>
<tr>
<td>
Inicio del evento:
</td>
<td>
<!--Fecha de inicio del evento-->
<input type="date" class="in" name="txtini" readonly="readonly" value="<?php echo $var5 ?>"/>
</td>
</tr>
<tr>
<td>
Fin del evento:
</td>
<td>
<!--Fecha final del evento-->
<input type="date" class="in" name="txtfin" readonly="readonly" value="<?php echo $var6 ?>"/>
</td>
</tr>
<tr>
<td>
Duracion:
</td>
<td>
<!--Fecha final del evento-->
<input type="text" class="in" name="txtdia" readonly="readonly" value="<?php echo $var7 ?>"/>
</td>
</tr>
<tr>
<td>
Horas:
</td>
<td>
<!--Horas estimadas-->
<input type="text" class="in" name="txthor" readonly="readonly" value="<?php echo $var8 ?>"/>
</td>
</tr>


<tr>
<td>
Depósito confirmado:
</td>
<td>
<!--Fecha de entrada del depósito en el banco-->
<input type="checkbox" class="in" name="txtdep" readonly="readonly" value="<?php echo $var9 ?>"/>
</td>
</tr>
<tr>
<td>
Fecha depósito:
</td>
<td>
<!--Fecha de entrada del depósito en el banco-->
<input type="date" class="in" name="txtfde" readonly="readonly" value="<?php echo $var10 ?>"/>
</td>
</tr>
<tr>
<td>
Depósito entregado:
</td>
<td>
<!--Depósito entregado-->
<input type="real" class="in" name="txtidp" readonly="readonly" value="<?php echo $var11 ?>" />
</td>
</tr>
<tr>
<td>
Total:
</td>
<td>
<!--Importe de los servicios requeridos-->
<input type="real" class="in" name="txtvpr" readonly="readonly" value="<?php echo $var12 ?>" />
</td>
</tr>
<tr>
<td>
Coste servicios:
</td>
<td>
<!--Coste de los servicios requeridos-->
<input type="real" class="in" name="txtcos" readonly="readonly" value="<?php echo $var13 ?>" />
</td>
</tr>
<tr>
<td>
Resultado:
</td>
<td>
<!--Importe de los servicios requeridos-->
<input type="real" class="in" name="txtres" readonly="readonly" value="<?php echo $var14 ?>" />
</td>
</tr>
<tr>
<td>
Fecha de factura:
</td>
<td>
<!--Importe de los servicios requeridos-->
<input type="date" class="in" name="txtfac" readonly="readonly" value="<?php echo $var15 ?>"/>
</td>
</tr>
<tr>
<td>
Número de factura:
</td>
<td>
<input type="text" class="in" name="txtffa" readonly="readonly" value="<?php echo $var16 ?>" />
</td>
</tr>
<tr>
<td>
Servicios:
</td>
<td>
<input type="text" class="in" name="txtser" readonly="readonly" value="<?php echo $var17 ?>" />
</td>
</tr>
<tr>
<td>
Observaciones:
</td>
<td>
<textarea name="txtobs" cols=40 rows=3 value="<?php echo $var18 ?>">

</textarea>
</td>
</tr>

</table>
<input type="submit" name="btn1" value="Primero"/>
<input type="submit" name="btn1" value="Anterior"/>
<input type="text" class="vis" name="txtvariable" value="<?php echo $cont ?>"/>
<input type="submit" name="btn1" value="Siguiente"/>
<input type="submit" name="btn1" value="Ultimo"/>
<?php echo "<font size=2> de ".$totreg."</font>";?>
<p></p>

<!--<tr>
<td colspan="2" align="left">-->
<div>
<input type="submit" name="btn1" value="Nuevo"/>
<input type="button" name="btn1" value="Modificar" onclick="modificar()"/>
<input type="submit" name="btn1" value="Buscar"/>
<input type="submit" name="btn1" value="Eliminar"/>
<input type="submit" id="pinchable" name="btn2" value="Aceptar"/>
<input type="reset" name="btn2" value="Cancelar" onclick="cancelar()"/>

</div>
<!--</td>
</tr>-->
</form>

</body>
</html>

Etiquetas: boton, evento, formulario, submit
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:41.