Toujours aussi nul en javascript, j'aimerai ajouter une boucle while dans la fonction afficher.



pour faire un tableau de 7 lignes maximum et du nombre de colonnes tant qu'il y aura des réponses.
voici le code
Code : Tout sélectionner
function afficher()
{
while (this.afficher < 7){
w.document.writeln( '<table><tr><td><h3><a target="_blank" rel="noopener" href=' + this.url + '>' + this.titre + '</a></h3></td></tr></table>' );
while (this.afficher >7 and this.afficher < 14){
w.document.writeln( '<table><tr><td><h3><a target="_blank" rel="noopener" href=' + this.url + '>' + this.titre + '</a></h3></td></tr></table>' );
while (this.afficher >14and this.afficher < 21){
w.document.writeln( '<table><tr><td><h3><a target="_blank" rel="noopener" href=' + this.url + '>' + this.titre + '</a></h3></td></tr></table>' );
while (this.afficher >21 and this.afficher < 28){
w.document.writeln( '<table><tr><td><h3><a target="_blank" rel="noopener" href=' + this.url + '>' + this.titre + '</a></h3></td></tr></table>' );
while (this.afficher >28 ){
w.document.writeln( '<h3>TROP DE RÉPONSES ! AJOUTER UN MOT CLE</h3>' );
}
}
function Stock( titre_in,keyword_in,url_in )
{
this.titre = titre_in;
this.keyword = keyword_in;
this.url = url_in;
this.afficher = afficher;
}
/* Cette fonction réécrit entièrement la page web pour y afficher les résultats */
function rechercher( chaine )
{
var trouved = 0;
chaine = chaine.toUpperCase();
var data = new Array();
store( data );
w=open('index.html','','');
/*w.document.writeln( "<html><head><title>Résultats de la recherche</title><link href='css.css' rel='stylesheet' type='text/css'></head>" );*/
/*w.document.writeln( "<body><div id='Corps'><h3>Résultats de la recherche "+chaine+"</h3></div>" );*/
w.document.writeln("<center><p style='color: blue; font-weight: bold;'><h3> Résultats de la recherche "+chaine+"</h3></p></center>");
for( var i=0; i<data.length ; i++ )
{
if(( data[i].titre.toUpperCase().indexOf( chaine ) != -1 )
|| ( data[i].keyword.toUpperCase().indexOf( chaine ) != -1 )
|| ( data[i].url.toUpperCase().indexOf( chaine ) != -1 ))
{
data[i].afficher();
trouved ++;
}
}
if( !trouved )
{
w.document.writeln( "<p style='color: red; font-weight: bold;'>Aucune réponse n'a été trouvée pour ce mot clé dans Base_Doc.</p>");
}
/*w.document.writeln( "<p style='color: blue; font-weight: bold;'>"+trouved+" réponse(s) trouvée(s) pour le mot-clé "+chaine);*/
w.document.writeln( "</p><hr><form><input type='button' value='Nouvelle recherche ?' OnClick='window.location=\"index.html\"'></form></div>" );
w.document.writeln( "</body></html>" );
w.document.close();
}
//-->
</script>