Foros del Web » Programando para Internet » Javascript »

Juntar 2 scripts en una funcion Onclick, EN un Buscador Interno html

Estas en el tema de Juntar 2 scripts en una funcion Onclick, EN un Buscador Interno html en el foro de Javascript en Foros del Web. Hola amigos estoy intentando que este buscador en Javascript para mi web, se diriga a la palabra, de busqueda, directamente, por ejemplo si tengo una ...
  #1 (permalink)  
Antiguo 16/08/2012, 22:38
 
Fecha de Ingreso: agosto-2008
Mensajes: 48
Antigüedad: 15 años, 8 meses
Puntos: 0
Juntar 2 scripts en una funcion Onclick, EN un Buscador Interno html

Hola amigos estoy intentando que este buscador en Javascript para mi web, se diriga a la palabra, de busqueda, directamente, por ejemplo si tengo una lista de 100 elementos, y busco el 100, El buscador me dice que si hay 1 resultado, pero no se dirige hacia la palabra buscada por si mismo, uno tiene que buscarla dentro de la web para verla, si esta en el pie de pagina.


Como puedo hacer que el buscador, despues de mandar el Alert, me diriga a la palabra buscada solito,?




Código Javascript:
Ver original
  1. <script>
  2. var texto="";
  3. function resaltar(){
  4. var encontro=0;
  5. var donde=0;
  6. valor=document.getElementById('tt').value;//caja de texto con id="tt"///
  7. reemplazar=RegExp(valor,"i");
  8. if(texto==""){texto=document.body.innerHTML};
  9. txt=texto.split(">");
  10. for (x=0;x<txt.length;x++){
  11. desde=(txt[x].indexOf("<")!=-1)?txt[x].indexOf("<"):0;
  12. tempP=txt[x].slice(0,desde);
  13. tempU=txt[x].slice(desde);
  14. tempPx=tempP.split(" ");
  15. for(y=0;y<tempPx.length;y++){
  16. if(tempPx[y].search(reemplazar)!=-1 && tempPx[y].length==valor.length){
  17. tempPx[y]="<span style=\u0022background-Color:yellow;\u0022>"+tempPx[y]+"</span>";
  18. encontro+=1;
  19. }
  20. }
  21. txt[x]=tempPx.join(" ")+tempU;
  22. }
  23. document.body.innerHTML=txt.join(">");
  24. alert((encontro==0)?"No se encontro ''"+valor+"''":"Se encontraton "+encontro+" coincidencias");
  25. }
  26.  
  27.  
  28. </script>
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. <input type="text" name="textfield" id="tt" onChange="n = 0;">
  36. <input type="button" value="Buscar en el documento" onClick="resaltar()">
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. <span id="aa"> </span></p>
  44. <p>JScript es un lenguaje <strong>de <em>secuencias</em></strong> de comandos<em>
  45. interpretado</em> y basado en objetos. Aunque tiene menos funciones que los
  46. lenguajes orientados a objetos de altas prestaciones como C++, JScript es muy
  47. eficiente para los prop&oacute;sitos<font color="#FF0000" face="Arial, Helvetica, sans-serif"> a los que se destina.</font>
  48. </p>
  49. <p></p>

Última edición por cerd0; 16/08/2012 a las 23:09
  #2 (permalink)  
Antiguo 16/08/2012, 23:10
 
Fecha de Ingreso: agosto-2008
Mensajes: 48
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: Juntar 2 scripts en una funcion Onclick, EN un Buscador Interno html

Tengo otro codigo de buscador que si hace esa funcion, de ir a la palabra de busqueda automaticamente, pero en su defecto no me resalta la palabra buscada. ya intente de varias formas hacer que trabajen juntos, o de unir ambos codigos, pero no puedo, por favor alguien puede hecharme una mano?

Ya intente separar las funciones en el evento con punto y coma ; para que se ejecuten ambas, pero no logro hacerlo de otras formas ya no se que mas intentar.

Este ES EL BUSCADOR que va a la palabra buscada automatico


Código Javascript:
Ver original
  1. </script>
  2.  
  3.  
  4. <script language="JavaScript">
  5. <!-- More javascripts http://www.hypergurl.com -->
  6.  
  7. var NS4 = (document.layers);    // Which browser?
  8. var IE4 = (document.all);
  9.  
  10. var win = window;    // window to search.
  11. var n   = 0;
  12.  
  13. function findInPage(str) {
  14.  
  15.   var txt, i, found;
  16.  
  17.   if (str == "")
  18.     return false;
  19.  
  20.   // Find next occurance of the given string on the page, wrap around to the
  21.   // start of the page if necessary.
  22.  
  23.   if (NS4) {
  24.  
  25.     // Look for match starting at the current point. If not found, rewind
  26.     // back to the first match.
  27.  
  28.     if (!win.find(str))
  29.       while(win.find(str, false, true))
  30.         n++;
  31.     else
  32.       n++;
  33.  
  34.     // If not found in either direction, give message.
  35.  
  36.     if (n == 0)
  37.       alert("Not found.");
  38.   }
  39.  
  40.   if (IE4) {
  41.     txt = win.document.body.createTextRange();
  42.  
  43.     // Find the nth match from the top of the page.
  44.  
  45.     for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
  46.       txt.moveStart("character", 1);
  47.       txt.moveEnd("textedit");
  48.     }
  49.  
  50.     // If found, mark it and scroll it into view.
  51.  
  52.     if (found) {
  53.       txt.moveStart("character", -1);
  54.       txt.findText(str);
  55.       txt.select();
  56.       txt.scrollIntoView();
  57.       n++;
  58.     }
  59.  
  60.     // Otherwise, start over at the top of the page and find first match.
  61.  
  62.     else {
  63.       if (n > 0) {
  64.         n = 0;
  65.         findInPage(str);
  66.       }
  67.  
  68.       // Not found anywhere, give message.
  69.  
  70.       else
  71.         alert("Not found.");
  72.     }
  73.   }
  74.  
  75.   return false;
  76. }
  77.  
  78. </script>
  79.  
  80.  
  81.  
  82.  
  83. <body bgcolor="#FFFFFF" text="#000000">
  84. <p>
  85.  
  86.  
  87. <form name="search" onSubmit="return findInPage(this.string.value);">
  88. <input name="string" id="buscador" type="text" size=15 onChange="n = 0;">
  89.  <input type="submit" value="Search Page"></form>


Muchas gracias

Etiquetas: funcion, html, input, js, juntar, onclick, scripts, select, buscadores
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 20:24.