IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

onkeyup ne fonctionne pas


Sujet :

Langage PHP

  1. #1
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mars 2012
    Messages : 6
    Points : 4
    Points
    4
    Par défaut onkeyup ne fonctionne pas
    j'utilise une fonction xajax qui affiche des données dans un tableau. Pour l'appel j'utilise l'évènement onkeyup dans le champ de texte de mon formulaire. Le problème c'est que pour 1,2,3 caractères cela ne marche pas (le curseur ne fait que tourner) mais lorsqu'on continu la saise à 4,5 caractères et plus la fonction marche parfaitement et affiche mes données. J'ai tout tenté (utilisation de onchange, onkeydown et des test sur ma fonction) mais en vain. Je souligne que le disfonctionnement est valable pour IE comme Mozilla firefox; Merci de m'aider car cela fait un bon moment que je cherche

  2. #2
    Modérateur

    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2007
    Messages
    1 996
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 996
    Points : 3 102
    Points
    3 102
    Par défaut
    Citation Envoyé par bgmis Voir le message
    Merci de m'aider car cela fait un bon moment que je cherche
    Bonjour,

    merci de nous montrer le code qui pourra nous permettre de t'aider. Sans cela, c'est "opération boule de cristal"...

  3. #3
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mars 2012
    Messages : 6
    Points : 4
    Points
    4
    Par défaut
    ok voici ou japel ma fonction:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    <form name="formdec" method="post" action="">
    <table width="100%" border="0">
    <tr>
    <td width="16%" align="right">Entreprise: </td>
    <td width="20%"><input type="text" name="nomentreprise" id="nomentreprise" size="40" onkeyup="<?php echo 'xajax_AfficheEntreprise(document.getElementById(\'nomentreprise\').value,formdec.ferm.checked,\''.$payss.'\');'; ?>" /></td>
    <td width="64%">Inclure les Entreprises Fermées : <input name="ferm" id="ferm" type="checkbox" onclick="<?php echo 'xajax_AfficheEntreprise(document.getElementById(\'nomentreprise\').value,formdec.ferm.checked,\''.$payss.'\');'; ?>" /></td>
    </tr>
    </table></form>
    Au fait j'ai passé 3 paramètres a ma fonction; il s'agit ici d'afficher la liste des entreprises par pays; le checkbox permet d'inclure simplement les entreprises fermées

  4. #4
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mars 2012
    Messages : 6
    Points : 4
    Points
    4
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    <?php 
    require_once('../Connections/connexion.php');
    if (isset($_GET['test'])) $payss=$_GET['test'];
    else $payss="0";
     
    #connexion à la BD
    $connexion = mysql_connect($hostname_connexion, $username_connexion, $password_connexion);
    #Sélection de la BD
    mysql_select_db($database_connexion, $connexion); 
     
    // Fonction qui affiche les entreprises en fonction du texte saisie :
    function AfficheEntreprise($valeure,$status,$paysss) {
    $reponse = new xajaxResponse();// Création d'une instance de xajaxResponse
      //création du tableau
     
    	if ($status=="") {	
    		if ($paysss==0){
    			$sql="SELECT DISTINCT entreprise.mat_entreprise, entreprise.situation_actuelle, entreprise.raison_sociale, entreprise.sigle, entreprise.adresse, entreprise.telephone1, entreprise.telephone2, entreprise.code_pays, entreprise.url_site, entreprise.email, entreprise.fax, entreprise.observation, entreprise.situation_geographique, pays.intitule_pays
    FROM entreprise, pays
    WHERE entreprise.code_pays=pays.code_pays AND (entreprise.sigle LIKE \"%$valeure%\" OR entreprise.raison_sociale LIKE \"%$valeure%\") AND entreprise.situation_actuelle='active'";
    		}
    		else {
    			$sql="SELECT DISTINCT entreprise.mat_entreprise, entreprise.situation_actuelle, entreprise.raison_sociale, entreprise.sigle, entreprise.adresse, entreprise.telephone1, entreprise.telephone2, entreprise.code_pays, entreprise.url_site, entreprise.email, entreprise.fax, entreprise.observation, entreprise.situation_geographique, pays.intitule_pays
    FROM entreprise, pays
    WHERE entreprise.code_pays=pays.code_pays AND entreprise.code_pays='$paysss' AND (entreprise.sigle LIKE \"%$valeure%\" OR entreprise.raison_sociale LIKE \"%$valeure%\") AND entreprise.situation_actuelle='active'";
    		}
    	}
    	else {
    		if ($paysss==0){
    			$sql="SELECT DISTINCT entreprise.mat_entreprise, entreprise.situation_actuelle, entreprise.raison_sociale, entreprise.sigle, entreprise.adresse, entreprise.telephone1, entreprise.telephone2, entreprise.code_pays, entreprise.url_site, entreprise.email, entreprise.fax, entreprise.observation, entreprise.situation_geographique, pays.intitule_pays
    FROM entreprise, pays
    WHERE entreprise.code_pays=pays.code_pays AND (entreprise.sigle LIKE \"%$valeure%\" OR entreprise.raison_sociale LIKE \"%$valeure%\")";
    		}
    		else {
    			$sql="SELECT DISTINCT entreprise.mat_entreprise, entreprise.situation_actuelle, entreprise.raison_sociale, entreprise.sigle, entreprise.adresse, entreprise.telephone1, entreprise.telephone2, entreprise.code_pays, entreprise.url_site, entreprise.email, entreprise.fax, entreprise.observation, entreprise.situation_geographique, pays.intitule_pays
    FROM entreprise, pays
    WHERE entreprise.code_pays=pays.code_pays AND entreprise.code_pays='$paysss' AND (entreprise.sigle LIKE \"%$valeure%\" OR entreprise.raison_sociale LIKE \"%$valeure%\")";
    		}
    	}
     
    	///////////////////////////////////////////////////////
     
    $query = mysql_query($sql) or die (mysql_error());
    $nbr=mysql_num_rows($query);
    $j=0;
    $nbr='<div id="nbreEntr" style="font-size:14px; text-align:left; color:#F00; font-family:Verdana, Geneva, sans-serif">Nombre d\'entreprises: '.$nbr.'</div>';
    $valeur = $nbr.'<table id="listeEntreprise" border=1 cellspacing=0 class="affich" >
    		   <thead>
    			<tr>
              <th width="10%">Matricule</th>
              <th width="25%">Raison Sociale</th>
              <th width="10%">Sigle</th>  
              <th width="15%">Adresse et Fax</th>
              <th width="10%">Site et Email</th>
              <th width="10%">Contacts</th>
              <th width="10%">Situation Géographique</th>
              <th width="10%">Pays</th>
            </tr>
    		  </thead>';
    $valeur.="<tbody>";
    while ($row = mysql_fetch_assoc($query))  {
    	$mat_entreprise=trim($row['mat_entreprise']);
    	$raison_sociale=htmlentities(trim($row['raison_sociale']), ENT_QUOTES);
    	$sigle=htmlentities(trim($row['sigle']), ENT_QUOTES);
    	$adr_fax='Adresse: '.htmlentities(trim($row['adresse']), ENT_QUOTES);
    	$adr_fax.='<br/>Fax: '.htmlentities(trim($row['fax']), ENT_QUOTES);
    	$contact='Contact1: '.trim($row['telephone1']);
    	$contact.='<br/>Contact2 :'.trim($row['telephone2']);
    	$sitemail='Site Web: '.htmlentities(trim($row['url_site']), ENT_QUOTES);
    	$sitemail.='<br/>Email: '.htmlentities(trim($row['email']), ENT_QUOTES);
    	$sitgeo=htmlentities(trim($row['situation_geographique']), ENT_QUOTES);
    	if (!empty($row['intitule_pays'])) $pay=htmlentities(trim($row['intitule_pays']), ENT_QUOTES);
    	//$valeur.='<tr class="row1"><td>'.$mat_entreprise.'</td><td>'.$raison_sociale.'</td><td>'.$sigle.'</td><td>'.$adr_fax.'</td><td>'.$sitemail.'</td><td>'.$contact.'</td><td>'.$sitgeo.'</td><td>'.$pay.'</td></tr>';
    	//cas 1 : l'entreprise est active alors on cherche dans la table produits_decision toutes ses décisions
    	if ($j % 2 == 0){
    		$valeur.="<tr class=\"row1\"><td>$mat_entreprise</td><td>$raison_sociale</td><td>$sigle</td><td>$adr_fax</td><td>$sitemail</td><td>$contact</td><td>$sitgeo</td><td>$pay</td></tr>"; } 
    	else {$valeur.="<tr><td>$mat_entreprise</td><td>$raison_sociale</td><td>$sigle</td><td>$adr_fax</td><td>$sitemail</td><td>$contact</td><td>$sitgeo</td><td>$pay</td></tr>";}
    	$j++;
    	}	
     
    	$valeur.='</tbody></table>';
     
    	$reponse->assign('resultat', 'innerHTML', $valeur);	
    	return $reponse; 
    }
     
    ?>
    ############### le formulaire
            <form name="formdec" method="post" action="">
        	  <table width="100%" border="0">
         	 <tr>
         	   <td width="16%" align="right">Entreprise: </td>
         	   <td width="20%"><input type="text" name="nomentreprise" id="nomentreprise" size="40" onkeyup="<?php echo 'xajax_AfficheEntreprise(document.getElementById(\'nomentreprise\').value,formdec.ferm.checked,\''.$payss.'\');';  ?>" /></td>
               <td width="64%">Inclure les Entreprises Fermées : <input name="ferm" id="ferm" type="checkbox" onclick="<?php echo 'xajax_AfficheEntreprise(document.getElementById(\'nomentreprise\').value,formdec.ferm.checked,\''.$payss.'\');'; ?>" /></td>
       	     </tr>
                </table></form>

  5. #5
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    Bonjour,

    Pourrais-tu également poster le code de xajax_AfficheEntreprise()

  6. #6
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mars 2012
    Messages : 6
    Points : 4
    Points
    4
    Par défaut
    le code de xajax_AfficheEntreprise()= fonction AfficheEntreprise() postée, je l'ai deja posté

  7. #7
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    Ok si je considère que tes appels ajax son correctes te passent tes données sans pertes (vu que je ne connais pas la lib xajax) voici un code plus propre.
    Appelles directement ton script AfficherEntreprises.php

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    <?php
    require_once('../Connections/connexion.php');
     
    #connexion à la BD
    $connexion = mysql_connect($hostname_connexion, $username_connexion, $password_connexion);
    #Sélection de la BD
    mysql_select_db($database_connexion, $connexion);
     
    $chars  = isset($_POST['chars'])  ? $_POST['chars']  : null; 
    $status = isset($_POST['status']) ? $_POST['status'] : null; 
    $pays   = isset($_POST['pays'])   ? $_POST['pays']   : null; 
     
    // Fonction qui affiche les entreprises en fonction du texte saisie :
    $reponse = new xajaxResponse();// Création d'une instance de xajaxResponse
     
    $sql = <<<SQL
       SELECT DISTINCT
          e.mat_entreprise,
          e.situation_actuelle,
          e.raison_sociale,
          e.sigle,
          e.adresse,
          e.telephone1,
          e.telephone2,
          e.code_pays,
          e.url_site,
          e.email,
          e.fax,
          e.observation,
          e.situation_geographique,
          p.intitule_pays
       FROM
          entreprise e
             INNER JOIN pays p ON e.code_pays = p.code_pays
    SQL;
     
    $where      = array();
    $safe_chars = mysql_real_escape_string($chars);
    $safe_pays  = mysql_real_escape_string($pays);
    $where[]    = "(e.sigle LIKE '%$safe_chars%' OR e.raison_sociale LIKE '%$safe_chars%')";
     
    if ($status === '') {
       $where[] = "entreprise.situation_actuelle='active'";
    }
     
    if ($pays != 0) {
       $where[] = "e.code_pays='$pays'";
    }
     
    if ( ! empty($where)) {
       $sql .= ' WHERE '.implode(' AND ', $where);
    }
     
    ///////////////////////////////////////////////////////
    $hes = function($p) { return htmlentities(trim($p), ENT_QUOTES); };
     
    $data = mysql_query($sql) or die (mysql_error());
    $nbr  = mysql_num_rows($data);
    $pair = true;
     
    $html = <<<HTML
    <div id="nbreEntr" style="font-size:14px; text-align:left; color:#F00; font-family:Verdana, Geneva, sans-serif">Nombre d'entreprises: $nbr</div>
    <table id="listeEntreprise" border="1" cellspacing="0" class="affich">
    <thead>
       <tr>
           <th width="10%">Matricule</th>
           <th width="25%">Raison Sociale</th>
           <th width="10%">Sigle</th>
           <th width="15%">Adresse et Fax</th>
           <th width="10%">Site et Email</th>
           <th width="10%">Contacts</th>
           <th width="10%">Situation Géographique</th>
           <th width="10%">Pays</th>
       </tr>
    </thead>
    <tbody>
    HTML;
    while($row = mysql_fetch_assoc($data)) {
       $class  = ($pair) ? ' class="row1"' : '';
       $pair   = ( ! $pair);
       $html  .= <<<HTML
       <tr$class>
          <td>{$hes($row['mat_entreprise'])}</td>
          <td>{$hes($row['raison_sociale'])}</td>
          <td>{$hes($row['sigle'])}</td>
          <td>
             Adresse: {$hes($row['adresse'])}<br />
             Fax: {$hes($row['fax'])}
          </td>
          <td>
             Site Web: {$hes($row['url_site'])}<br />
             Email: {$hes($row['email'])}
          </td>
          <td>
             Contact1: {$hes($row['telephone1'])}<br />
             Contact2: {$hes($row['telephone2'])}
          </td>
          <td>{$hes($row['situation_geographique'])}</td>
          <td>{$hes($row['intitule_pays'])}</td>
       </tr>
    HTML;
    }
     
    $html .= '</tbody></table>';
    $reponse->assign('resultat', 'innerHTML', $html);
    return $reponse;
    ?>
    Comme toujours ça sort du four, je n'ai rien testé.

Discussions similaires

  1. onkeyup qui ne fonctionne pas sous IE 9
    Par beegees dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 30/01/2012, 15h03
  2. Réponses: 6
    Dernier message: 27/01/2004, 11h14
  3. UNION qui ne fonctionne pas
    Par r-zo dans le forum Langage SQL
    Réponses: 7
    Dernier message: 21/07/2003, 10h04
  4. Un Hint sur un PopupMenu ne fonctionne pas !!??
    Par momox dans le forum C++Builder
    Réponses: 6
    Dernier message: 26/05/2003, 16h48
  5. ca ne fonctionne pas (generateur auto-incrémentant)
    Par tripper.dim dans le forum SQL
    Réponses: 7
    Dernier message: 26/11/2002, 00h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo