Foros del Web » Programando para Internet » PHP »

Pasar variables por JavaScript de un formulario a una página PHP

Estas en el tema de Pasar variables por JavaScript de un formulario a una página PHP en el foro de PHP en Foros del Web. hola tengo el siguiente problema, quiero pasar unas variables ya sea por javascript o jquery, hacia una pagina php para que esta me entregue los ...
  #1 (permalink)  
Antiguo 13/05/2014, 10:53
 
Fecha de Ingreso: junio-2013
Ubicación: santiago
Mensajes: 34
Antigüedad: 10 años, 10 meses
Puntos: 0
Mensaje Pasar variables por JavaScript de un formulario a una página PHP

hola tengo el siguiente problema, quiero pasar unas variables ya sea por javascript o jquery, hacia una pagina php para que esta me entregue los datos correspondientes

ahi esta el codigo!!

buscar.php
Código PHP:

  <form action="busqueda.php" id="formulario" method="post" name="formulario" onsubmit="onEnviar()">

    
    <div style="height:26px;"><select  name="select" id="ejemplar"><option value="er.NombreEjemplar">Ejemplar</option><option value="er.NombreJinete">Jinete</option><option value="er.NombrePreparador">Preparador</option><option value="NombreStud">Stud</option><!--option value="er.NombrePropietario">Propietario</option--><option value="NombreCriador">Criador</option>
    </select></div>

    <?php
    
require_once("admin/config.php");
    
mysql_connect(HOST,USER,PASS);
    
mysql_select_db(BBDD);
      
    
$sqleco ='SELECT DATE_FORMAT(FechaReunion, "%d-%c-%Y") as fecha, DATE_FORMAT(FechaReunion, "%Y-%c-%d") as fecha2 from CARRERAS group by FechaReunion ORDER BY `FechaReunion` DESC';
    
    
$rest mysql_query($sqleco);
    
?>
    <div style="height:25px;"> 
      <select id="fecha">
          <option value="">-Fecha-</option>
        <?php while ($apr mysql_fetch_assoc($rest)):?>
        <option value="<?php echo $apr['fecha2']?>"><?php echo actual_date($apr['fecha'])?></option>
        <?php endwhile; ?>
      </select></div>


    <div style="height:30px;"><input type="text" name="texto" id="texto"  />
    <button type="submit" value="Buscar" style="background:#2d3f63; color:#FFFFFF; font-family:century gothic; "/> buscar</button></div>
    </form>
  
  


  <script type="text/javascript">
    function onEnviar(){
    
      var ejemplar = document.formulario.ejemplar.value;
      var fecha = document.formulario.fecha.value;
      var texto = document.formulario.texto.value;
      //document.Buscar.submit();
       window.open("busqueda.php", '', 'location=no,scrollbars=no,resizable=no');
    }

</script>

busqueda.php

Código PHP:
<!-- los resultados -->
<style type="text/css">
.divcuerpo {    
    height: 0px;
    width: 470px;
    overflow-y:auto;
    overflow-x: hidden;
}  
table.estile td {    
    background:#2d3f63; 
    color:#FFFFFF;
    -moz-border-radius:25px 25px 0px 0px;

table.estile th {    
    border: 1px solid #000;
    background-color: #eee;
    text-align: center;

table.estail td {
    text-align: center;
    border: 1px solid #aaaaee;
    font-size:10px;
    line-height:100%;
    text-transform:capitalize;
    width:80px;
    max-width:78px;min-width:78px;
    overflow: hidden;
    padding:1px;
    border-collapse:separate;
    border-spacing:1px;
    -moz-border-radius: 5px 5px 0px 0px;
}
.cortar {
    overflow: hidden; 
    width: 78px; 
}
</style>
<table class="estile">
<tr><td colspan="6" align="center"><strong>RESULTADO DE BUSQUEDA</strong></td></tr>
<tr>
    <th align="center" width="26px">#</th>
    <th align="center" width="80px">Ejemplar</th>
<!--    <th align="center" width="80px">Prop.</th> -->
    <th align="center" width="80px">Prep.</th>
    <th align="center" width="80px">Jinete</th>
    <th align="center" width="80px" >Stud</th>
 </tr></table>
 <div id="bodirs" class="divcuerpo">
<table class="estail">
<?php 
require_once("admin/config.php");
mysql_connect(HOST,USER,PASS);
mysql_select_db(BBDD);
mysql_query("SET NAMES 'utf8'");

$query='SELECT e.NombreEjemplar, NombreJinete, NombrePreparador, er.NumeroCarrera,c.NumeroCarreraInterno, NombreStud, NombrePropietario, NumeroMandil, NombreCriador, DATE_FORMAT( er.FechaReunion,  "%d-%c-%Y" ) AS fecha 

        FROM  EJEMPLARES_REUNION er
        INNER JOIN EJEMPLARES e ON er.NombreEjemplar=e.NombreEjemplar
        INNER JOIN STUD ON STUD.Propietario=er.NombrePropietario
        INNER JOIN CARRERAS c ON c.FechaReunion=er.FechaReunion and c.NumeroCarrera=er.NumeroCarrera'
;

                

$query.="  WHERE ".mysql_real_escape_string(@$_REQUEST["ejemplar"])." like '%".mysql_real_escape_string(@$_REQUEST["texto"])."%'";

$query.=($_REQUEST["fecha"])? " AND er.FechaReunion = '".mysql_real_escape_string(@$_REQUEST["fecha"])."'":"";

$query.=" GROUP BY NombreEjemplar ORDER BY er.FechaReunion DESC";

//echo $query;

$resp mysql_query($query);

                
$sql2 "select * from EJEMPLARES_REUNION left join CARRERAS on (CARRERAS.NumeroCarrera = EJEMPLARES_REUNION.NumeroCarrera ) where EJEMPLARES_REUNION.FechaReunion = '".$row[FechaReunion]."' group by NumeroMandil";
                
//echo $sql2;
                
$rezul mysql_query($sql2);
                while(
$jin mysql_fetch_array($rezul)){
                    
//print_r($jin);
                    
echo "<a href='../detalle-programa-carreras.php?nc=".$row['NumeroCarrera']."'>".floatval($jin['NumeroCarreraInterno'])."ª</a>/".floatval($jin[NumeroMandil])."&nbsp;";
                }
while (
$rowmysql_fetch_array($resp)) {

    echo 
"<tr>
        <td  width=\"24px\" style=\"max-width:24px;min-width:24px;\"><a href='../detalle-programa-carreras.php?nc="
.$row['NumeroCarrera']."&fecha=".$_REQUEST["fecha"]."'>".floatval($row['NumeroCarreraInterno'])."ª</a></td> 

        <td  width=\"19px\" style=\"text-align: left;font-weight:bold;\"><div class=\"cortar\">"
.strtolower($row['NombreEjemplar']). "</div></td> 
    <!-- <td width=\"80px\"><div class=\"cortar\">"
.$row['NombrePropietario']. "</div></td> -->
        <td width=\"80px\"><div class=\"cortar\">"
.$row['NombrePreparador']. "</div></td> 
        <td width=\"80px\"><div class=\"cortar\">"
$row['NombreJinete']. "</div></td>
        <td ><div class=\"cortar\">"
$row['NombreStud']. "</div></td><tr>";
}
while(
$jin mysql_fetch_array($rezul)){
                    
//print_r($jin);
                    
echo "<a href='../detalle-programa-carreras.php?nc=".$jin[1]."'>".floatval($jin['NumeroCarreraInterno'])."ª</a>/".floatval($jin[NumeroMandil])."&nbsp;";    
                }
?> 
</table></div>
  #2 (permalink)  
Antiguo 13/05/2014, 12:48
Avatar de Alexis88
Philosopher
 
Fecha de Ingreso: noviembre-2011
Ubicación: Tacna, Perú
Mensajes: 5.552
Antigüedad: 12 años, 5 meses
Puntos: 977
Respuesta: Pasar variables por JavaScript de un formulario a una página PHP

Solo bastaba con que adjuntes las variables a la URI.

Código Javascript:
Ver original
  1. function onEnviar(){
  2.     var ejemplar = document.formulario.ejemplar.value,
  3.         fecha = document.formulario.fecha.value,
  4.         texto = document.formulario.texto.value,
  5.         uri = "busqueda.php?ejemplar=" + ejemplar + "&fecha=" + fecha + "&texto=" + texto;
  6.  
  7.     window.open(uri, '', 'location=no,scrollbars=no,resizable=no');
  8. }

Debiste publicar este hilo en el foro de JavaScript, acá PHP no tiene nada que ver.

Saludos
__________________
«Juro por mi vida y mi amor por ella, que jamás viviré para el provecho de otro hombre, ni le pediré a otro hombre que viva para el mío».

Ayn Rand

Etiquetas: fecha, formulario, java, mysql, select, sql, variable, variables
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:29.