[RESOLU] Afficher une fonction dans une DIV

Pour toutes les discussions javascript, jQuery et autres frameworks
Répondre
Serenodo
Messages : 11
Enregistré le : 18 févr. 2020, 14:36
Localisation : Savigny le temple
Contact :

[RESOLU] Afficher une fonction dans une DIV

Message par Serenodo » 11 mars 2020, 08:17

Bonjour,
Encore grâce à ce site, j'ai pu avoir ce que je recherchais.
Maintenant est-il possible de récupérer une fonction dans une div. OU dans un tableau.

Mais le:
return(1) doit s'afficher dans la div <div id="CorpsLeft"> OU <TD>1
return(2) doit s'afficher dans la div <div id="CorpsCenter> OU TD> 2
return(3) doit s'afficher dans la div <div id="CorpsRight"> OU <TD>3
Voici le code

Code : Tout sélectionner

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Base de Connaissance</title>
    <script type = 'text/javascript'>


	function store (data)
	{
		data[0]=new Stock("BIBLI POUR CONTES","","02-2020","doc/Bpc.pdf" );
		data[1]=new Stock("CONNEXION ENTRE DEUX SCENES","","02-2020","doc/connexion.pdf" );
		data[2]=new Stock("PERSONNAGE ","","03-2020","doc/personnage.pdf" );
		data[3]=new Stock("MATRICE NOUVELLE","","03-2020","doc/NouvelleMatrice.pdf" );
		data[4]=new Stock("REVISION RELECTURE RAPIDE","","03-2020","doc/RelectureRapide.pdf" );
		/*data[5]=new Stock("","","","doc/");*/
		/*data[6]=new Stock("","","","doc/");*/
		/*data[7]=new Stock("","","","doc/");*/
		/*data[8]=new Stock("","","","doc/");*/
		/*data[9]=new Stock("","","","doc/");*/
		/*data[10]=new Stock("","","","doc/");*/
		/*data[11]=new Stock("","","","doc/");*/
		/*data[12]=new Stock("","","","doc/");*/
		/*data[13]=new Stock("","","","doc/");*/
		/*data[14]=new Stock("","","","doc/");*/
		/*data[15]=new Stock("","","","doc/");*/
		/*data[16]=new Stock("","","","doc/");*/
		/*data[17]=new Stock("","","","doc/");*/
		/*data[18]=new Stock("","","","doc/");*/
		/*data[19]=new Stock("","","","doc/");*/
		/*data[20]=new Stock("","","","doc/");*/
		/*data[21]=new Stock("","","","doc/");*/
		/*data[22]=new Stock("","","","doc/");*/
		/*data[23]=new Stock("","","","doc/");*/
		/*data[24]=new Stock("","","","doc/");*/
		/*data[25]=new Stock("","","","doc/");*/
		/*data[26]=new Stock("","","","doc/");*/
		/*data[27]=new Stock("","","","doc/");*/
		/*data[28]=new Stock("","","","doc/");*/
		/*data[29]=new Stock("","","","doc/");*/
		/*data[30]=new Stock("","","","doc/");*/
		/*data[31]=new Stock("","","","doc/");*/
		/*data[32]=new Stock("","","","doc/");*/
		/*data[33]=new Stock("","","","doc/");*/
		/*data[34]=new Stock("","","","doc/");*/
		/*data[35]=new Stock("","","","doc/");*/
		/*data[36]=new Stock("","","","doc/");*/
		/*data[37]=new Stock("","","","doc/");*/
		/*data[38]=new Stock("","","","doc/");*/
		/*data[39]=new Stock("","","","doc/");*/
		/*data[40]=new Stock("","","","doc/");*/
		/*data[41]=new Stock("","","","doc/");*/
		/*data[42]=new Stock("","","","doc/");*/
		/*data[43]=new Stock("","","","doc/");*/
		/*data[44]=new Stock("","","","doc/");*/	
	}

	/*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>' );
		}
	}*/
	

	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 ))
			{
				if (trouved<11) {
					w.document.writeln( '<table><tr><td><h3><a target="_blank" rel="noopener" href=' + data[i].url + '>' + data[i].titre + '</a></h3></td></tr></table>' );
					return(1)
				} else if (trouved>10&&<21){
					w.document.writeln( '<table><tr><td><h3><a target="_blank" rel="noopener" href=' + data[i].url + '>' + data[i].titre + '</a></h3></td></tr></table>' );
					return(2)
				} else if (trouved>20&&<31){
					w.document.writeln( '<table><tr><td><h3><a target="_blank" rel="noopener" href=' + data[i].url + '>' + data[i].titre + '</a></h3></td></tr></table>' );
					return(3)
				}
				 else {
					 w.document.writeln( '<h3>TROP DE REPONSES ! AJOUTER UN MOT CLE</h3>' );
				}
				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>



</head>

<body>
	
	<div id="Header0">
	</div>
		<!--- HEADER --->
	<div id="Header1">
		
		<div class="HeaderRecherche">
			
			<center>
				<form name="rech" OnSubmit="rechercher( document.rech.champ.value );">
				<input type="text" name="champ"    size="70"><BR>
				<input type="submit" name="valide" value="Rechercher">
				</form>


				<noscript><p>
				Votre navigateur ne reconnait pas le JavaScript, le script de recherche ne pourra pas marcher.
				</p></noscript>
			</center>
			
		</div>
		
	</div>
	<!--- END HEADER --->
	<!--- CENTRAL --->
	<div id="Corps">
		<div id="CorpsLeft">
		REPONSES DE 0 A 10
		</div>
		<div id="CorpsCenter">
		REPONSE DE 11 A 21
		</div>
		<div id="CorpsRight">
		REPONSES DE 22 A 32
		</div>
		
	</div>
	<!--- END CENTRAL --->
	<!--- FOOTER --->
	<div id="Footer">
	<!--- Tableau  6 Colonnes -- 10 Lignes dont une en titre-->
	<table>
		<!--- TITRES--->
		<thead>	
		<tr>
		<th><span style='color:black; font-weight:bold' >WEB</span> </th>
		<th><span style='color:black; font-weight:bold' >MEMO</span> </th>
		<th><span style='color:black; font-weight:bold' >ANNUAIRES</span> </th>
		<th><span style='color:black; font-weight:bold' >DICTIONNAIRE</span> </th>
		<th><span style='color:black; font-weight:bold' >MODELES</span> </th>
		<th><span style='color:black; font-weight:bold' >SITES</span> </th>
		</tr>
		</thead>	
		<!--- Ligne1 --->
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		</tr>
		<!--- Ligne3--->
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		</tr>
		<!--- Ligne4--->
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		</tr>
		<!--- Ligne5--->
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>	
		</tr>
		<!--- Ligne6 --->
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		</tr>
		<!--- Ligne7 --->
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		</tr>
		<!--- Ligne8 --->
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		</tr>
		<!--- Ligne9 --->
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		</tr>
		<!--- Ligne10 --->
		<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		</tr>
		</table>
	</div>
	<!--- END FOOTER --->
</body>
</html>
Merci
Modifié en dernier par Serenodo le 16 mars 2020, 11:41, modifié 1 fois.
" L'écriture est mon rempart conte la folie " ----- " Ne laissez personne détruire vos rêves "

Avatar du membre
webmaster
Administrateur du site
Messages : 563
Enregistré le : 28 févr. 2017, 15:19

Re: Afficher une fonction dans une DIV

Message par webmaster » 16 mars 2020, 11:26

Bonjour

Il faut absolument ouvrir la console du navigateur pour regarder les erreurs
La ligne 97 est pas bonne : if (trouved>10&&<21)

Le code est tres strict
on ecrit
if ((trouved>10)&& (trouved<21))

Ensuite, pour remplacer une zone, il faut utiliser innerHTMl
Voir ici :
https://www.toutjavascript.com/referenc ... erhtml.php
TJS : 25 ans et mon livre Tout JavaScript chez Dunod
https://www.toutjavascript.com/livre/index.php

Serenodo
Messages : 11
Enregistré le : 18 févr. 2020, 14:36
Localisation : Savigny le temple
Contact :

Re: Afficher une fonction dans une DIV

Message par Serenodo » 16 mars 2020, 11:40

Bonjour,
Merci pour ton aide.
" L'écriture est mon rempart conte la folie " ----- " Ne laissez personne détruire vos rêves "

Répondre