Foros del Web » Programando para Internet » Javascript »

Cual es el problema de este JS ???

Estas en el tema de Cual es el problema de este JS ??? en el foro de Javascript en Foros del Web. Hola a todos: Genere este JS en el HTML de un PHP ... Código HTML: <table border=1 cellpadding=0 cellspacing=0 bordercolor=555555 width=680> <tr> <td align=center width=80> ...
  #1 (permalink)  
Antiguo 01/01/2006, 21:46
Avatar de BLAH !!  
Fecha de Ingreso: septiembre-2003
Ubicación: Región Metropolitana, Santiago, Chile
Mensajes: 706
Antigüedad: 20 años, 7 meses
Puntos: 16
Cual es el problema de este JS ???

Hola a todos:

Genere este JS en el HTML de un PHP ...

Código HTML:
 <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>
<table border="0" cellpadding="0" cellspacing="0" width="680">
<script>
function cambio( region1 ) {
  document.cotizacion.articulo1.length =0;
  document.cotizacion.valor1.length =0;
  switch ( region1 )  {
    case 'albaca1': {
      document.cotizacion.articulo1.value = 'Respuesta 1';
      document.cotizacion.valor1.value = '1'}
      break;
    case 'barra1': {
      document.cotizacion.articulo1.value = 'Respuesta 2';
      document.cotizacion.valor1.value = '2'}
      break;
    case 'cara1': {
      document.cotizacion.articulo1.value = 'Respuesta 3';
      document.cotizacion.valor1.value = '3'}
      break;
  }
}
</script>
      <tr> 
       <td align=center width=80><input type=text name=cantidad1 id=cantidad1 size=5></td> 
       <td align=center width=100>
        <select type=text name=item1 id=item1 onChange='cambio(this.value)'>
	 <option value='0' selected>ITEM</option>
         <option value='albaca1'>A-098</option>
         <option value='barra1'>A-099</option>
         <option value='cara1'>A-100</option>
        </select></td> 
       <td align=center width=220><textarea cols=22 rows=2 name=articulo1 id=articulo1></textarea></td> 
       <td align=center width=140>$ <input type=text name=valor1 id=valor1 size=10 onKeyUp="javascript: document.getElementById('total1').value = document.getElementById('valor1').value * document.getElementById('cantidad1').value;" onMouseMove="javascript: document.getElementById('total1').value = document.getElementById('valor1').value * document.getElementById('cantidad1').value;"></td> 
       <td align=center width=140>$ <input type=text name=total1 id=total1 size=10></td> 
      </tr>
<script>
function cambio( region2 ) {
  document.cotizacion.articulo2.length =0;
  document.cotizacion.valor2.length =0;
  switch ( region2 )  {
    case 'albaca2': {
      document.cotizacion.articulo2.value = 'Respuesta 1';
      document.cotizacion.valor2.value = '1'}
      break;
    case 'barra2': {
      document.cotizacion.articulo2.value = 'Respuesta 2';
      document.cotizacion.valor2.value = '2'}
      break;
    case 'cara2': {
      document.cotizacion.articulo2.value = 'Respuesta 3';
      document.cotizacion.valor2.value = '3'}
      break;
  }
}
</script>
      <tr> 
       <td align=center width=80><input type=text name=cantidad2 id=cantidad2 size=5></td> 
       <td align=center width=100>
        <select type=text name=item2 id=item2 onChange='cambio(this.value)'>
	 <option value='0' selected>ITEM</option>
         <option value='albaca2'>A-098</option>
         <option value='barra2'>A-099</option>
         <option value='cara2'>A-100</option>
        </select></td> 
       <td align=center width=220><textarea cols=22 rows=2 name=articulo2 id=articulo2></textarea></td> 
       <td align=center width=140>$ <input type=text name=valor2 id=valor2 size=10 onKeyUp="javascript: document.getElementById('total2').value = document.getElementById('valor2').value * document.getElementById('cantidad2').value;" onMouseMove="javascript: document.getElementById('total2').value = document.getElementById('valor2').value * document.getElementById('cantidad2').value;"></td> 
       <td align=center width=140>$ <input type=text name=total2 id=total2 size=10></td> 
      </tr></table> 

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

Si se fijan, hay 2 JS iguales que actuan en diferentes SELECT ....... me funciona solamente el último select siempre ... los otros no (trabajo con crecion automatica de filas, he ahi el motivo de tantos numeros)

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

Otra consulta ... no hay alguna forma de que en un JS como este, (FIJENSE EN LOS PARENTESIS DE CORCHETE) pueda poner como nombre del input de un formulario los mismos parentesis de corchetes (no funciona con ellos)

Código HTML:
<script>
function cambio( region[COLOR="Red"][2][/COLOR] ) {
  document.cotizacion.articulo[COLOR="Red"][2][/COLOR].length =0;
  document.cotizacion.valor[COLOR="Red"][2][/COLOR].length =0;
  switch ( region[COLOR="Red"][2][/COLOR] )  {
    case 'albaca[COLOR="Red"][2][/COLOR]': {
      document.cotizacion.articulo[COLOR="Red"][2][/COLOR].value = 'Respuesta 1';
      document.cotizacion.valor[COLOR="Red"][2][/COLOR].value = '1'}
      break;
    case 'barra[COLOR="Red"][2][/COLOR]': {
      document.cotizacion.articulo[COLOR="Red"][2][/COLOR].value = 'Respuesta 2';
      document.cotizacion.valor[COLOR="Red"][2][/COLOR].value = '2'}
      break;
    case 'cara[COLOR="Red"][2][/COLOR]': {
      document.cotizacion.articulo[COLOR="Red"][2][/COLOR].value = 'Respuesta 3';
      document.cotizacion.valor[COLOR="Red"][2][/COLOR].value = '3'}
      break;
  }
}
</script> 
__________________
Adios ...!!!!
  #2 (permalink)  
Antiguo 01/01/2006, 22:01
Avatar de BLAH !!  
Fecha de Ingreso: septiembre-2003
Ubicación: Región Metropolitana, Santiago, Chile
Mensajes: 706
Antigüedad: 20 años, 7 meses
Puntos: 16
AL FIN !!!!

El problema estaba en que estoy dando la misma funcion name a los dos script por lo que solo le cambio el nombre
__________________
Adios ...!!!!
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 09:34.