Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/07/2011, 20:00
ignacio350
 
Fecha de Ingreso: junio-2011
Ubicación: Ccs
Mensajes: 27
Antigüedad: 12 años, 10 meses
Puntos: 3
Ejecutar funcion al seleccionar un checkbox

Buenas noches amigos de la comunidad, tengo un problemita:

Tengo un proyecto que se basa en un sistema para Agencias de Viajes, entonces se pueden comprar o reservar boletos, al momento que un usuario reserve un boleto el tendra una opcion para cambiar el estado a comprado.

Entonces yo tengo el siguiente codigo:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>

<body>

<?php
session_start
();
if(!isset(
$_SESSION["login"])){ ?>
<fieldset id="identi"> 
<legend align="center">ALERTA</legend>
<p align="center" >No ha iniciado sesion <a href="login.php">Identifiquese</a> en nuestro sistema.</p><br>
<p align="center" >Sino esta registrado puede  <a href="registro.php">Registrarse</a></p><br>
</fieldset> 

<?php
} else {
 
$conexion=mysql_connect('localhost','ignacio','xtreme') or die (mysql_error());
 
$db=mysql_select_db('agencia') or die (mysql_error());
 
$login=$_SESSION['login'];
 
$query="SELECT id,codavion,origen,destino,partida,llegada,fechaida,puesto,clase,aerolinea FROM boletos WHERE login='$login' AND estado='reservado'";
 
 
$result=mysql_query($query);
 
$row=mysql_fetch_row($result);
 
?>
 <table width="60%" height="49" border="1"> 
 <tr>
    <th > Vuelo </th>
    <th > Origen </th>
    <th > Destino </th> 
    <th > Hora de Ida </th>
    <th > Hora de Llegada </th>
    <th> Fecha </th> 
    <th > Asiento </th>
    <th > Clase </th>
    <th > Aerolinea </th>  
     <th> Seleccion </th>    </tr>
    
    <?php  
    
    
while($row=mysql_fetch_row($result))
    { 
?> 
     <tr>
    <?php
    
    
echo"<th>$row[1]</th>";
    echo
"<th>$row[2]</th>";
    echo
"<th>$row[3]</th>";
    echo
"<th>$row[4]</th>";
    echo
"<th>$row[5]</th>";
    echo
"<th>$row[6]</th>";
    echo
"<th>$row[7]</th>";
    echo
"<th>$row[8]</th>";
    echo
"<th>$row[9]</th>";
    echo
"<th>$row[0]<input type='checkbox' name='$row[0]' value='$row[0]'  id='row0_0'></th>";
     
    
   echo 
"</tr>";
}
 
 
  
   
 
   
 echo 
"</table>";
     }
?>
</body>
</html>
Lo que necesito hacer es que cuando seleccione un checkbox se ejecute una funcion para actualizar el boleto a comprado

para eso tengo esta consulta
Código MySQL:
Ver original
  1. $query2="UPDATE boletos SET estado='comprado' WHERE id='$row[0]'";
  2. $result2=mysql_query($query2);

y tambien que cada vez que se ejecute la funcion se actualice la pagina.

Pero no se como hacer esto con Javascript, gracias de antemano.



EDIT: ,busque info sobre AJAX y me tope con una propiedad onchange="this.form.submit()" no es precisamente AJAX pero hace la funcion que necesito cuando seleccionen un checkbox yo poder saber cual seleccionar y poder hacer mi consulta. Pense que era mas dificil pero fue sencillo habia que buscar un poco y pensar :D.

Última edición por ignacio350; 11/07/2011 a las 23:42