Bonjour à tous!,
J'ai besoin de votre aide car je ne comprends pas tout.
j'ai fait en javscript un petit support de recherche.
Le principe :
j'ai une base de fichier accessible par un fichier .js
grâce à une requête XMLHTTP je rapatrie le contenu de chaque fichier
ensuite je cherche si le mot clé est dedans
si oui j'affiche les fichiers dans lesquels il est présent
problème : avec le document.write l'affichage me donne 7 résultats pour une bonne réponse ?????
VOICI le fichier de recherche :
<html><head><title>La fouine</title>
<SCRIPT language="javascript" src="FICHIERS.js"></SCRIPT>
<style>A:link{text-decoration: underline;color: BLACK;font-family: Arial;font-size: 9pt;font-
style:normal;font-weight: bold;}A:visited{text-decoration: overline underline;color: RED;font-
family: Arial;font-size: 9pt;font-style: none;font-weight: normal;}A:active{text-decoration:
overline underline;color:green;font-family:Arial;font-size:10pt;font-style:none;font-
weight:normal;}A:hover{text-decoration: overline underline;color:BLACK;font-family: Comic Sans
MS;font-size: 10pt;font-style: none;font-weight:bold;}td {color: BLUE;font-family: Arial;font-
size: 12pt;}.d{width:1;visibility:hidden}</style>
<SCRIPT type=Text/JavaScript>function changer(C){
document.getElementById('S').value = ((document.getElementById('C').value).replace
(/à/g,"à").replace(/é/g,"é").replace(/ù/g,"ù").replace
(/è/g,"è").replace(/ê/g,"ê").replace(/â/g,"â").replace
(/ô/g,"ô").replace(/î/g,"î").replace(/ç/g,"ç")) ;}</SCRIPT>
<script type="text/javascript">
var IE = (document.all);
var a_win = window;
var a_n = 0;
var a_txt, a_i, a_trouve;
function afftxt(){
for (var a=0;a<fichier.length;a++)
{ for (var contenu in fichier[a])
(document.getElementById('R').value = fichier[a][0]);
/////////REQUETE XMLHTTPREQUEST POUR RAPATRIER LE CONTENU DES FICHIERS DU JS//////////
var xhr_object = null;
if ( window.ActiveXObject ) {
xhr_object = new ActiveXObject( 'Microsoft.XMLHTTP' );
} else {alert( 'Votre navigateur ne supporte pas les objets XMLHTTPRequest...' );
return;
}xhr_object.open( 'GET', document.getElementById('R').value, false );
xhr_object.send( null );
if ( xhr_object.readyState == 4 ) {
document.getElementById( 'D' ).value = xhr_object.responseText;}
{if (document.getElementById('S').value == "")
return false;}
//////////////EN DESSOUS REMISE A BLANC DU TRUE POUR NOUVELLE RECHERCHE///////////
document.getElementById("E").value = "";
///////////////en dessous se fait la recherche//////////////
if (IE) {
a_txt = a_win.document.search.D.createTextRange();
for (a_i = 0; a_i <= a_n && (a_trouve = a_txt.findText(document.getElementById('S').value)) !=
false; a_i++);
if (a_trouve) {a_n++;
document.getElementById('E').value = a_txt.findText(document.getElementById('S').value);}
else {
if (a_n > 0) {
a_n = 0;}}
///////FIN DE LA RECHERCHE SI TRUE RAPATRIEMENT///////////
alert('test1');
if(document.getElementById("E").value == "true")
{
for (var j=0; j<fichier[a][0].length;j++){
document.write(fichier[a][0]);
document.write("<br>");}
document.getElementById("B").style.visibility='hidden';
}
}}}
function TOUT(){
afftxt();
}</script>
</head><body onLoad="document.search.C.focus();" bgcolor="#CCFFCC">
<form name="search">
<input type=button
OnClick="TOUT();"
value="Lancer"style="width:60;background:'#FFFFCC';color:navy;"onmouseover="this.style.background
Color='#00FF00';this.style.color='red';"
onmouseout="this.style.backgroundColor='#FFFFCC';this.style.color='navy';">
<input type=text Id="C" onKeyUp="changer(document.search.C.value);"
onClick="document.getElementById('O').innerHTML='';document.getElementById
('T').innerHTML='';document.getElementById('B').innerHTML='';document.getElementById
('S').value='';document.getElementById('E').value='';document.getElementById
('R').value='';document.getElementById('D').value='';">
<BR>
<DIV style=width:350;background:pink;color:navy><b><CENTER>RESULTAT(S) ICI</CENTER></b></DIV><div
Id="O" style=color:red;></div>
<DIV style=width:350;background:pink;>
<CENTER><table width=350 border=1><tr style=color:navy><td width=80%
align=center><b>DESCRIPTION</b></td></tr></table></CENTER></DIV>
<DIV Id=T style=position:absolute;top:200;width:350;background:yellow align=center></DIV><div
Id="B" style=position:absolute;top:200;width:350;background:yellow;visibility:visible
align=center></div>
<BR>
<div Id="Q" style=visibility:visible></div>
<textarea Id="D" cols=10 rows=10 style=visibility:visible></textarea>
<input type=text Id=E style=width:150;visibility:visible><br>
<INPUT TYPE=TEXT Id=R style=width:150;visibility:visible>
<input type=text Id=S style=width:100;visibility:visible>
</form></body></html>
ICI LE FICHIER nom : fichiers.js
var fichier=new Array();
fichier[0] = new Array("0.html");
fichier[1] = new Array("0.html");
fichier[2] = new Array("0.html");
fichier[3] = new Array("0.html");
fichier[4] = new Array("0.html");
fichier[5] = new Array("55.html");
fichier[6] = new Array("0.html");
fichier[7] = new Array("0.html");
fichier[8] = new Array("0.html");
fichier[9] = new Array("55.html");
et la le 0.html
<html>
<head>
</head>
HELLO
<body>
</body>
et la le 55.html
<html>
<head>
</head>
5555
<body>
</body>
MERCI POUR VOS IDEES

