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 :

Problème champs txtbox


Sujet :

JavaScript

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 5
    Par défaut Problème champs txtbox
    bonjour, je suis actuellement en train de faire un formulaire d'inscription pour un repas dansant j'ai presque fini mais j'ai un problème, j'aimerais pouvoir remettre le champs nombre de place si celui ci n'est pas rempli et qu'il a était vidé. Par défault le champ est a 0, mais par exemple si l'utilisateur vide le champs j'aimerais que le 0 revienne dans le champs car en bas de bas il y'a un champ prix à payer qui se calcul tout seul et si le champ n'a pas la valeur 0 et qu'il est vide il m'affiche une erreur au total.

    merci d'avance pour votre réponse

  2. #2
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 5
    Par défaut
    les scripts utliser :

    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
    <script>
    function C1()
    {
      var v1 = parseInt(document.getElementById("I1A").value);
      var v2 = parseInt(document.getElementById("I1B").value);
     
      document.getElementById("ST1").value = v1*16 + v2*8;
    }
     
     
    function verif_nombre(champ)
    {
    var chiffres = new RegExp("[0-9\.]"); /* Modifier pour : var chiffres = new RegExp("[0-9]"); */
    var verif;
    var points = 0; /* Supprimer cette ligne */
     
    for(x = 0; x < champ.value.length; x++)
    {
    verif = chiffres.test(champ.value.charAt(x));
    if(champ.value.charAt(x) == "."){points++;} /* Supprimer cette ligne */
    if(points > 1){verif = false; points = 1;} /* Supprimer cette ligne */
    if(verif == false){champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); x--;}
    }
     
    }
     
    </script>

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 5
    Par défaut
    et le formulaire

    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
    <table border="0" cellpadding="0" cellspacing="0" width="585" height="354">
        <tr>
          <td align="right" height="25" width="143">Nom :&nbsp;</td>
          <td height="25" width="438">&nbsp;<input type="text" name="T1" size="38"></td>
        </tr>
        <tr>
          <td align="right" height="25" width="143">Prénom :&nbsp;</td>
          <td height="25" width="438">&nbsp;<input type="text" name="T1" size="38"></td>
        </tr>
        <tr>
          <td align="right" height="138" width="143">Adresse :&nbsp;</td>
          <td height="138" width="438">&nbsp;<textarea rows="6" name="S1" cols="29"></textarea></td>
        </tr>
        <tr>
          <td align="right" height="25" width="143">Réservation :</td>
          <td height="25" width="438">&nbsp;
    <input type="text" name="Adulte" id="I1A"  value="0" onchange="C1()" onFocus="this.value=''" 
     
    onkeyup="verif_nombre(this);" size="5">Place(s) Adulte [ <b>16</b>
            € ]</td>
        </tr>
        <tr>
          <td align="right" height="25" width="143"></td>
          <td height="25" width="438">&nbsp;
    <input type="text" name="Enfant" id="I1B" value="0" onchange="C1()" onFocus="this.value=''" 
     
    onkeyup="verif_nombre(this);" size="5">  Place(s) Enfant
            (<i>- de 16 ans</i>) [ <b>8</b> € ]</td>
        </tr>
        <tr>
          <td align="right" height="49" width="143"></td>
        </center>
        <td height="49" width="438">
          <p align="center">
    <input type="button" onclick="C1()" value="Calculer le prix"></td>
      </tr>
      <center>
      <tr>
        <td align="right" height="21" width="143"></td>
        <td height="21" width="438"></td>
      </tr>
      <tr>
        <td align="right" height="25" width="143">Prix à payer :</td>
        <td height="25" width="438">&nbsp;<input type="text" id="ST1" readonly/ size="14">
          €</td>
      </tr>
      <tr>
        <td align="right" height="21" width="143"></td>
        <td height="21" width="438"></td>
      </tr>
      <tr>
        <td align="right" height="21" width="143"></td>
        <td height="21" width="438"><input type="submit" value="Envoyer" name="B1" 
     
    onClick="this.form.submit();this.disabled=true;this.value='Patientez...'"></td>
      </tr>
      </table>

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2002
    Messages
    214
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 214
    Par défaut
    salut,
    pour faire simple, je ferais un test dans la fonction de calcul:

    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
     
    function C1()
    {
    var v1 = document.getElementById("I1A").value;
    var v2 = document.getElementById("I1B").value;
     
    if (v1=='') {
    v1=0;
    document.getElementById("I1A").value=0;
    }
    else {v1=parseInt(v1);}
    if (v2==''){
    v2=0;
    document.getElementById("I1B").value=0;
    }
    else {v2=parseInt(v2);}
     
    document.getElementById("ST1").value = v1*16 + v2*8;
    }

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 5
    Par défaut
    merci bcp sa va m'aider a mieux comprendre

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 5
    Par défaut
    es-ce que il aurait la possibilité de remettre aussi les valeurs d'origine dans le champ vide automatiquement ?

Discussions similaires

  1. [Tableaux] Problème champ textarea
    Par christophe42 dans le forum Langage
    Réponses: 4
    Dernier message: 02/02/2006, 17h45
  2. Problème champs calculés et valeur null
    Par markintell dans le forum Access
    Réponses: 18
    Dernier message: 10/01/2006, 18h14
  3. Problème champ après import d'excel vers access
    Par David M dans le forum Access
    Réponses: 6
    Dernier message: 16/10/2005, 11h53
  4. problème champ date dans base oracle
    Par ludovik dans le forum Oracle
    Réponses: 6
    Dernier message: 25/07/2005, 15h48
  5. Problème champs de type texte.
    Par Le-Cortex dans le forum Access
    Réponses: 7
    Dernier message: 06/01/2005, 14h42

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