Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/09/2015, 09:35
Avatar de bymorr
bymorr
 
Fecha de Ingreso: septiembre-2012
Mensajes: 118
Antigüedad: 11 años, 8 meses
Puntos: 9
Respuesta: Como puedo sacar el id que se muestra en mi dado

Primero que todo trataría de hacerlo mas simple, utilizando funciones javascript o jquery.

Código HTML:
Ver original
  1.     function lanzar_dado(){
  2.         posibles_numeros = 6 - 1 //Mayor - Menor
  3.         numero_dado = Math.random() * posibles_numeros;
  4.         var valor= Math.round(parseInt(1)+numero_dado);
  5.         document.getElementById("valor").value=valor;
  6.     }
  7.  
  8.  
  9. </head>
  10.  
  11. <input type="button" value="Lanzar" onclick="lanzar_dado()">
  12. <input type='text' id='valor' />
  13. </body>
  14. </html>

Ahora si quieres del modo que tu lo hiciste, puede que te sirva esto:

Código HTML:
Ver original
  1. <title> DADO </title>
  2. <style type="text/css">
  3. span {display: none;}
  4. button {display: block;}
  5. <script type="text/javascript">
  6. var VanillaRunOnDomReady = function() {
  7. var boton = document.getElementById("id_boton"),
  8.     cuarz = document.getElementsByTagName("div"),
  9.     total = cuarz.length,
  10.     forEach = Array.prototype.forEach;
  11. // var posicion=0;
  12. boton.addEventListener("click", function () {
  13.     var num=0;
  14.     var otro='';
  15.     var i = 0,
  16.      
  17.         intervalo = setInterval(function () {
  18.             if ((i += 100) < 3000) {
  19.                var posicion = Math.floor(Math.random() * total);
  20.                forEach.call(cuarz, function (estilo) {
  21.                    estilo.style.display = estilo == cuarz[posicion] ? "block" : "none";
  22.                     otro =posicion; // defino la posicion del id.
  23.                    
  24.                 });            
  25.            } else{
  26.                 console.log(otro);
  27.                 alert(otro);
  28.                 clearInterval(intervalo);
  29.                
  30.            
  31.             }
  32.        }, 100);
  33.        
  34. }, false);
  35.  
  36.  
  37. }
  38.  
  39. var alreadyrunflag = 0;
  40.  
  41. if (document.addEventListener)
  42.    document.addEventListener("DOMContentLoaded", function(){
  43.        alreadyrunflag=1;
  44.        VanillaRunOnDomReady();
  45.        
  46.    }, false);
  47. else if (document.all && !window.opera) {
  48.    document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
  49.     var contentloadtag = document.getElementById("contentloadtag")
  50.     contentloadtag.onreadystatechange=function(){
  51.         if (this.readyState=="complete"){
  52.             alreadyrunflag=1;
  53.             VanillaRunOnDomReady();
  54.         }
  55.     }
  56. }
  57. function llamar(){  // creo funcion
  58.    
  59. setTimeout("if (!alreadyrunflag){VanillaRunOnDomReady}", 0);
  60.  
  61. }
  62. // window.onload = function(){    //saque el window load y declare una funcion.
  63.   // setTimeout("if (!alreadyrunflag){VanillaRunOnDomReady}", 0);
  64. // }
  65.  
  66.  
  67. </head>
  68.  
  69. <?php // VARIABLES DE IDS
  70. $a = ('ID  '. 1);   // ordeno todo los arreglos
  71. $b = ('ID  '. 2);
  72. $c = ('ID  '. 3);
  73. $d = ('ID  '. 4);
  74. $e = ('ID  '. 5);
  75. $f = ('ID  '. 6);
  76. ?>
  77. <form action="" method="post">
  78. <div id='0' style="display: none;"><?php echo $a; ?></div> <!-- ordeno los arreglos -->
  79. <div id='1' style="display: none;"><?php echo $b; ?></div>
  80. <div id='2' style="display: none;"><?php echo $c; ?></div>
  81. <div id='3' style="display: none;"><?php echo $d; ?></div>
  82. <div id='4' style="display: none;"><?php echo $e; ?></div>
  83. <!-- Por defecto -->
  84. <div id='5' style="display: block;"><?php echo $f; ?></div>
  85. </form>
  86. <br>
  87. <button style="margin-left:20px;" type="button" onclick='llamar();' value="Lanzar Dado" name="button" id="id_boton">¡Lanzar!</button>
  88.  
  89.  
  90.  
  91. </body></html>

1.- saque window load. y lo cambie por una función para llamar a través de un onclick.
2.- ordene tus div y tus valores.
3.- en tu función declaro un campo otro el cual es la posición del div y que coincide con el id.

eso por lo menos cumple lo que tu necesitas, pero insisto hay formas mas fáciles y con menos lineas de código.