Ver Mensaje Individual
  #4 (permalink)  
Antiguo 19/07/2008, 11:21
Avatar de Un_Tico
Un_Tico
 
Fecha de Ingreso: julio-2008
Ubicación: Cartago, Costa Rica
Mensajes: 176
Antigüedad: 15 años, 9 meses
Puntos: 4
Respuesta: Como hago para mostrar datos de una lista desplegable en la misma pagina ?

Código:
<?php
$conexion=mysql_connect("localhost","root","xxxxxx ") or die("Problemas en la conexion");
mysql_select_db("empresa",$conexion) or die("Problemas en la selección de la base de datos");
if(isset($_POST['ok'])){
	mysql_query("update mi_tabla set nombre='".$_POST['name']."'where codigo=".$_POST['code']);
}
?>
<!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>Untitled Document</title>
<script type="text/javascript">
function get_name_from_list(){
	if(document.getElementById('names_list')){
		if(document.getElementById('code')){
			if(document.getElementById('name')){
				var code = document.getElementById('names_list').options[document.getElementById('names_list').selectedIndex].value;
				var name = document.getElementById('names_list').options[document.getElementById('names_list').selectedIndex].text;
				document.getElementById('code').value=code;
				document.getElementById('name').value=name;
			}else{
				alert('Element name not found!!!');
			}
		}else{
			alert('Element code not found!!!');
		}
	}else{
		alert('Element names_list not found!!!');
	}
}
</script>
</head>
<body>
<?php
$result=mysql_query("SELECT * FROM materia_prima order by codigo ", $conexion);
?>
<form id="form1" name="form1" method="post" action="">
  <label>
  <select name="names_list" id="names_list" onchange="get_name_from_list()">
    <option>Select One</option>
    <?php
	while ($row1=mysql_fetch_array($result)){
	?>
    	<option value="<?=$row1["codigo"]?>"><?=$row1["codigo"].$row1["nombre"]?></option>
    <?php
	}
	?>
  </select>
  </label>
Nombre
<input type="hidden" name="code" id="code" />
<label>
<input type="text" name="name" id="name" />
</label>

<label>
<input type="submit" name="ok" id="ok" value="ok" />
</label>
</form>
</body>
</html>
O algo asi.. Suerte, pero siempre antes de preguntar intenta hacerlo tu primero, investiga...

Saludos...