Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/10/2011, 08:11
Avatar de Jask
Jask
 
Fecha de Ingreso: abril-2006
Ubicación: Madrid
Mensajes: 773
Antigüedad: 18 años, 1 mes
Puntos: 15
Respuesta: Duda sobre obtener el nombre del ID

Cita:
Iniciado por IsaBelM Ver Mensaje
el error lo tienes aquí

es minúscula
Mira, te cuento lo que he hecho:

Código HTML:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2.    "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="es">
  4. <!--
  5.    Crear un formulario con tres botones con las leyendas "1", "2" y "3". Mostrar un mensaje indicando qué botón se presionó.
  6. -->
  7.     <title>Javascript</title>
  8.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  9.    
  10.     <script type="text/javascript">
  11.         function verContenido(id){
  12.             alert(document.getElementById(id).value);
  13.         }
  14.     </script>
  15.    
  16. </head>
  17.     <h1>Pulsa cualquier botón</h1>
  18.     <form name="botones" method="post" action="#">
  19.         <input type="button" value="1" name="boton" id="boton1" onclick="verContenido(this.id)">
  20.         <input type="button" value="2" name="boton" id="boton2" onclick="verContenido(this.id)">
  21.         <input type="button" value="3" name="boton" id="boton3" onclick="verContenido(this.id)">
  22.     </form>
  23.    
  24. </body>
  25. </html>

Cuando hago this.id me devuelve el valor de la ID de ese button, pero me gustaría saber si hay otra opción de poner this.id porque si hago un getElementById tengo qu especificar el Id que quiero "observar" pero yo quiero saber como se "llama" ese id !!

Gracias
__________________
Os iusti meditabitur sapientiam
Si te he ayudado, por qué no un poquito de Karma :) ?