Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/12/2005, 18:54
Avatar de BLAH !!
BLAH !!
 
Fecha de Ingreso: septiembre-2003
Ubicación: Región Metropolitana, Santiago, Chile
Mensajes: 706
Antigüedad: 20 años, 7 meses
Puntos: 16
Exclamación Relleno automático según listbox

Hola a todos:

Tengo un formulario que me crea filas con celdas automaticamente de acuerdo a mis necesidades. Con este código

Código HTML:
<BODY bgcolor="ffffff" text="#000000" leftMargin="10" topMargin="10">
<center>
<FONT COLOR=000000 SIZE=4 FACE=Arial>
 Seleccione el número de articulos que son
</FONT>
<form action="<?=$_SERVER["PHP_SELF"]?>" method="get"> 
<select name="filas"> 
<? for($i=1; $i<=20; $i++){ 
echo "<option value='".$i."'>".$i."</option>"; 
}?> 
</select> 
<input type="hidden" name="crear" value="tabla"> 
<input type="submit" value="crear"> 
</form> 

--------------------------------------------------------------------
Este código actua en este formulario

Código HTML:
<form name="cotizacion" method="post" action="email.php" onSubmit="return chkcotizacion()">
 <table border="0" width=100% cellpadding=0 cellspacing=0>
   <tr>
   <td align=center colspan=2 width=100%>
     <table border=1 cellpadding=0 cellspacing=0 bordercolor=555555 width=680>
      <tr>
       <td align=center width=80>
        <font face="Arial, Helvetica, sans-serif" color="000000" size=3><b>CANT.</b></font>
       </td>
       <td align=center width=100>
        <font face="Arial, Helvetica, sans-serif" color="000000" size=3><b>ITEM</b></font>
       </td>
       <td align=center width=220>
        <font face="Arial, Helvetica, sans-serif" color="000000" size=3><b>ARTICULO</b></font>
       </td>
       <td align=center width=140>
        <font face="Arial, Helvetica, sans-serif" color="000000" size=3><b>V/UNIT.</b></font>
       </td>
       <td align=center width=140>
        <font face="Arial, Helvetica, sans-serif" color="000000" size=3><b>TOTAL</b></font>
       </td>
      </tr>
     </table>
<? 
if(isset($_GET["crear"])){ 
    echo '<table border="0" cellpadding="0" cellspacing="0" width="680">'; 
   for($i=1; $i<=$_GET["filas"]; $i++){ 
        echo " 
      <tr> 
       <td align=center width=80><input type=text name=cantidad[$i] id=cantidad[$i] size=5></td> 
       <td align=center width=100><input type=text name=item[$i] id=item[$i] size=7></td> 
       <td align=center width=220><textarea cols=22 rows=2 name=articulo[$i] id=articulo[$i]></textarea></td> 
       <td align=center width=140>$ <input type=text name=valor[$i] id=valor[$i] size=10  onKeyUp=\"javascript: document.getElementById('total[$i]').value = document.getElementById('valor[$i]').value * document.getElementById('cantidad[$i]').value;\"></td> 
       <td align=center width=140>$ <input type=text name=total[$i] id=total[$i] size=10></td> 
      </tr>"; 
    } 
    echo "</table>"; 
} 
?> 
-------------------------------------------------------------

Si se fijan debo poner en el NAME="" de cada input del formulario un [$i] que será el número de acuerdo a las filas que cree en un principio.

-------------------------------------------------------------

Todo bien hasta aca. Pero ahora quiero hacer que el <input name="item[$i]"> sea un select que al elejir una de sus options me complete automaticamente el textarea Articulo[$i] y el input valor[$i] .

Esto lo logro con este java ... veanlo

Código HTML:
<script>
function cambio( region ) {
  document.form.comboB.length =0;
  switch ( region )  {
    case 'baleares': {
      document.form.comboB.value = "Respuesta 1";
      document.form.texto.value = "Respuesta 1.1"}
      break;
    case 'catalunya': {
      document.form.comboB.value = "Respuesta 2";
      document.form.texto.value = "Respuesta 2.2"}
      break;

    case 'galicia':  {
      document.form.comboB.value = "Respuesta 3";
      document.form.texto.value = "Respuesta 3.3"}
      break;
  }
}
</script>


<form name="form" method="post" action="">
  <select name="comboA" onChange="cambio(this.value)">
      <option value="0" selected>ITEM</option>
      <option value="baleares">Baleares</option>
      <option value="catalunya">Cataluña</option>
      <option value="galicia">Galicia</option>
  </select>
  <textarea name="comboB">
  </textarea>
  <input type="text" name="texto" value="">
</form> 
---------------------------------------------------------------

El problema es que este Java no me sirve ya que al completar de acuerdo a mi formulario los nombres de el textarea y el input no me funcionan (deben ser ARTICULO[$i] y VALOR[$i].

He ahí mi problema no se como arreglar este problema, es por eso que recurro a PHP para ver si hay una forma de completar un textarea y un input solamente con la eleccion de una option de un select.
__________________
Adios ...!!!!