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

JavaScript Discussion :

[débutant] saisie de texte


Sujet :

JavaScript

  1. #1
    Membre du Club Avatar de benoitB
    Profil pro
    Inscrit en
    Août 2002
    Messages
    78
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : France

    Informations forums :
    Inscription : Août 2002
    Messages : 78
    Points : 68
    Points
    68
    Par défaut [débutant] saisie de texte
    Bonjour,
    Un textbox qui :
    1. si contient du texte induit un checkbox coché
    2. si ne contient rien induit un checkbo non coché

    Après recherche et codage, j'ai :
    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
    <html>
       <head>
          <title>EAU</title>
          <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
          <link rel="stylesheet" type="text/css" href="css.css" /> 
       </head>
       <script type="text/javascript"><!--
          function radio_nomDuLaboratoireAction (_f)
          {
             if( !_f.document.getElementById('radio_nomDuLaboratoire').checked ) _f.document.getElementById('texte_nomDuLaboratoire').value = "";
          }
          function radio_nomDuLaboratoireSaisie (_f)
          {
             var valeur = _f.document.getElementById('texte_nomDuLaboratoire').value;
             if( valeur.length == 0 )
                _f.document.getElementById("radio_nomDuLaboratoire").checked = "false";
             else
                _f.document.getElementById("radio_nomDuLaboratoire").checked = "true";
          }
     
          function timer() {
             radio_nomDuLaboratoireSaisie(document.forms["denombrement"]);
             setTimeout("timer()", 3000);
          }
       --></script>
       <body background="" style="margin:0px;" onload="timer();">
          <form name="denombrement">
             <a name="_top"></a>
             <table bgcolor="white" style="border: 0px solid black;" align="center" border="0" cellpadding="0" cellspacing="0" width="800">
                <!-- ****************************** zone riche ****************************** -->
                </tr>
                   <td style="background-color:#ECEEF6;" valign="Top">
                      <h1>Donn&eacute;es de tra&ccedil;abilit&eacute; &amp; de calcul</h1>
                      <fieldset style="WIDTH:100%; border:0px solid Black;">
                      <table width=100% border=1>
                      <tr>
                      <td width=5%></td>
                      <td width=5% align=center>
                      <input type="checkbox" id="radio_nomDuLaboratoire" onclick="radio_nomDuLaboratoireAction(this.form);" style="vertical-align: middle" />
                      </td>
                      <td width=40% align=Right>Nom du laboratoire&nbsp;</td>
                      <td width=40% align=center><input type="text" id="texte_nomDuLaboratoire" onChange="" maxlength=50 style="vertical-align: middle; width: 100%" /></td>
                      <td width=5%></td>
                      </tr>
                      </table>
                      </fieldset>
                      <br>
                   </td>
                </tr>
             </table>
             <a name="_bottom"></a>
          </form>
       </body>
    </html>
    Le but est bien entendu de surveiller (fonction timer()) le texte contenu dans le textebox et de cocher ou décocher automatiquement si il y a du texte ou non.
    Sauf que toutes les 3 secondes (délibérément long pour le voir, je le placerai à 100ms) le checkbox se coche même si le textbox n'a pas de contenu,

    Merci par avance

  2. #2
    Expert éminent sénior

    Homme Profil pro
    Inscrit en
    Janvier 2007
    Messages
    13 474
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2007
    Messages : 13 474
    Points : 36 571
    Points
    36 571
    Par défaut
    Bonjour,
    a priori, il faut enlever les "_f" quand tu utilises getElementById : cette syntaxe est indépendante du <form> ...

    A+
    Pour tout savoir sur l'utilisation du forum

    En postant votre message, n'oubliez pas les Règles du Club.

  3. #3
    Membre du Club Avatar de benoitB
    Profil pro
    Inscrit en
    Août 2002
    Messages
    78
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : France

    Informations forums :
    Inscription : Août 2002
    Messages : 78
    Points : 68
    Points
    68
    Par défaut pareil...
    Après ré-écriture :
    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
    <html>
       <head>
          <title>EAU</title>
          <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
          <link rel="stylesheet" type="text/css" href="aes.css" /> 
       </head>
       <script type="text/javascript"><!--
          function radio_nomDuLaboratoireAction ()
          {
             if( !document.getElementById('radio_nomDuLaboratoire').checked ) document.getElementById('texte_nomDuLaboratoire').value = "";
          }
          function texte_nomDuLaboratoireSaisie ()
          {
             var valeur = document.getElementById('texte_nomDuLaboratoire').value;
             if( valeur.length > 0 )
                document.getElementById("radio_nomDuLaboratoire").checked = "true";
             else
                document.getElementById("radio_nomDuLaboratoire").checked = "false";
          }
     
          function timer()
          {
             texte_nomDuLaboratoireSaisie();
             setTimeout("timer()", 3000);
          }
       --></script>
       <body background="" style="margin:0px;" onload="timer();">
          <form name="denombrement">
             <a name="_top"></a>
             <table bgcolor="white" style="border: 0px solid black;" align="center" border="0" cellpadding="0" cellspacing="0" width="800">
     
                <tr>
                   <td style="background-color:#ECEEF6;" valign="Top">
                      <br>
                      <br>
                      <h1>Donn&eacute;es de tra&ccedil;abilit&eacute; &amp; de calcul</h1>
                      <fieldset style="WIDTH:100%; border:0px solid Black;">
                         <table width=100% border=1>
                            <tr>
                               <td width=5%></td>
                               <td width=5% align=center>
                                  <input type="checkbox" id="radio_nomDuLaboratoire" onclick="radio_nomDuLaboratoireAction();" style="vertical-align: middle" />
                               </td>
                               <td width=40% align=Right>Nom du laboratoire&nbsp;</td>
                               <td width=40% align=center><input type="text" id="texte_nomDuLaboratoire" onkeypress="texte_nomDuLaboratoireSaisie();" maxlength="50" style="vertical-align: middle; width: 100%" /></td>
                               <td width=5%></td>
                            </tr>
                         </table>
                      </fieldset>
                   </td>
                </tr>
             </table>
             <a name="_bottom"></a>
          </form>
       </body>
    </html>
    C'est pareil, le checkbox se coche tout seul, je le décoche et dès que la méthode timer est lancée il devien coché.

  4. #4
    Expert éminent sénior

    Homme Profil pro
    Inscrit en
    Janvier 2007
    Messages
    13 474
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2007
    Messages : 13 474
    Points : 36 571
    Points
    36 571
    Par défaut
    blabla.checked = false ou true
    pas "false" ou "true" ...
    Bref : enlève les ""
    Pour tout savoir sur l'utilisation du forum

    En postant votre message, n'oubliez pas les Règles du Club.

  5. #5
    Expert éminent sénior

    Homme Profil pro
    Inscrit en
    Janvier 2007
    Messages
    13 474
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2007
    Messages : 13 474
    Points : 36 571
    Points
    36 571
    Par défaut
    Citation Envoyé par E.Bzz
    blabla.checked = false ou true
    pas "false" ou "true" ...
    Bref : enlève les ""
    Précision et explication : en JS (et ailleurs) :
    0 = false
    autre chose = true

    Pour désactiver tu fais
    ...checked = "false"
    comme "false" est différent de la valeur 0, ton "false" vaut ... true
    Pour tout savoir sur l'utilisation du forum

    En postant votre message, n'oubliez pas les Règles du Club.

  6. #6
    Membre du Club Avatar de benoitB
    Profil pro
    Inscrit en
    Août 2002
    Messages
    78
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : France

    Informations forums :
    Inscription : Août 2002
    Messages : 78
    Points : 68
    Points
    68
    Par défaut
    Oui merci je viens aussi de le découvrir, en tout cas merci.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débutant]Changer du text dans un tableau
    Par Azimel dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 17/09/2005, 18h38
  2. Réponses: 2
    Dernier message: 08/08/2005, 11h27
  3. [c#]Champs de saisie de texte
    Par Verboz dans le forum ASP.NET
    Réponses: 5
    Dernier message: 03/05/2005, 15h01
  4. saisi champs texte
    Par j2zetka dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 01/12/2004, 14h01
  5. [Débutant] SWT: composant Texte avec \n
    Par bonnefr dans le forum SWT/JFace
    Réponses: 3
    Dernier message: 18/05/2004, 11h44

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