Ver Mensaje Individual
  #2 (permalink)  
Antiguo 25/10/2010, 11:14
Avatar de Markgus
Markgus
 
Fecha de Ingreso: junio-2010
Mensajes: 152
Antigüedad: 13 años, 11 meses
Puntos: 5
Respuesta: cargar valores de un select a input text y tambien a otro select

encontre la manera de cargar los select con el jquery pero pues o me agarra el id para el select dependiente o para los text, alguna ide de como podria juntar esto?

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script type="text/javascript" src="jquery.js"></script>
        <script language="JavaScript" type="text/JavaScript">
            $(document).ready(function(){
                $("#cliente").change(function(event){
                    var id = $("#cliente").find(':selected').val();
                    $("#select2").load('pruebaSel.php?id='+id);
                });
            });
        </script>
    </head>
<body>
 <form>
<SELECT NAME="cliente" id="cliente" SIZE="1"><OPTION VALUE=""></OPTION>
<?
include("config.php");
$query="SELECT id_usuarios, username FROM usuarios as U
inner join tipos_de_sistemas as TS on U.id_sistema = TS.id_sistema;
";
$result = mysql_query($query) or die ( mysql_error() );
while ($row=mysql_fetch_array($result))
{

  if($_GET['id_usuarios'] == $row['id_usuarios']){
       echo "<OPTION VALUE='". $row['id_usuarios'] ."' selected>". $row['username'] ."</OPTION>";
       
 }else{
      echo "<OPTION VALUE='". $row['id_usuarios'] ."'>". $row['username'] ."</OPTION>";
 }

}
?>
</SELECT>
 <select name="select2" id="select2">
</select>
</form>
</body>
</html>
pruebaSel.php

Código PHP:
<?php
include("config.php");
$query="SELECT id_usuarios, username FROM usuarios as U
inner join tipos_de_sistemas as TS on U.id_sistema = TS.id_sistema
 WHERE id_usuarios = "
.$_GET['id'];
$result mysql_query($query) or die ( mysql_error() );
while (
$row=mysql_fetch_array($result))
{

  if(
$_GET['id_sistema'] == $row['id_sistema']){
       echo 
"<OPTION VALUE='"$row['id_sistema'] ."' selected>"$row['nombre_sistema'] ."</OPTION>";
       
 }else{
      echo 
"<OPTION VALUE='"$row['id_sistema'] ."'>"$row['nombre_sistema'] ."</OPTION>";
 }

}
?>