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 :

transtypage object en javascript


Sujet :

JavaScript

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    129
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 129
    Points : 43
    Points
    43
    Par défaut transtypage object en javascript
    Bonsoir tt le monde ,

    je voudrais savoir , comment on transtype un Object en integer
    par exemple

    object = document.getElementByName("txt").

    merci d'avance de votre aide.

  2. #2
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    transtyper un objet en integer ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    document.getElementsByName('txt')
    je ne comprends pas le but de la manoeuvre ...

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    129
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 129
    Points : 43
    Points
    43
    Par défaut
    transtyper l'objet et l'affecter à une variable de type int , c ça que je voulais dire .
    merci

  4. #4
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    var monobjet= ParseInt(document.getElementsByName("txt")[0].value)
    ???

    comme ça ???

    à condition que l'objet nommé txt ait une value ...

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    129
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 129
    Points : 43
    Points
    43
    Par défaut
    merci SpaceFrog de m'avoir repondu,

    en faite voilà ma syntaxe se presente ainsi :


    ioObjet = document.getElementsByName(isName);
    iiElementIndex = parseInt(ioObjet(iiIndex -2));
    isLibelle = iiElementIndex.innerHTML;


    mon objectif est de récuperer les libellés de mon formulaire et je dois partir de l'iiIndex -2 à chaque fois , j'ai juste ces 2 derniere ligne à faire ou bien dans ma variable iiElementIndex.
    merci d'avance.

  6. #6
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    Très confus tout ça ...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    ioObjet = document.getElementsByName(isName); // ici tu as la collection des objets
    iiElementIndex = parseInt(ioObjet(iiIndex -2)); // là je sais pas ???
    // peut être:
    iiElementIndex = oiObjet[parseInt(iiIndex -2)]; 
    isLibelle = iiElementIndex.innerHTML;

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    129
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 129
    Points : 43
    Points
    43
    Par défaut
    merci de m'avoir encore repondu,

    je vais cherhcer quand même sur internet pour trouver ce probleme

    merci encore.

  8. #8
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    Non non on doit pouvoir resoudre ton problème ... mais comme on n'a pas le code html ... et que c'est pas très clair au niveau du resultat fianl attendu ...

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    129
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 129
    Points : 43
    Points
    43
    Par défaut
    voilà mon code :

    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
     
    <!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>
        <title>Page sans titre</title>
        <style>
        </style>
    </head>
    <body>
    <form>
     
     <table>
     
    <tr>
     <td>Nom:</td><td><input type="text" name="txtNom" maxlength="18" size="18" /></td>
     </tr>
     
     <tr>
     <td>Prénom:</td><td><input type="text" name="txtPrenom" maxlength="18" size="18" /></td>
     </tr>
     
     <tr>
     <td>Date de naissance:</td><td><input type="text" name=txtDateNaissance maxlength="18" size="18" /></td>
     </tr>
     
     <tr>
      <td>Sélectionner votre métier</td>
      <td>
           <select name="optMetier">
               <option value="01">biologiste</option>
               <option value="02">pilote</option>
               <option value="03">informaticien</option>
               <option value="04">mecanicien</option>
               <option value="05">astronaute</option>
               <option value="06">medecin</option>
               <option value="07">professeur</option>
           </select>
      </td>
      </tr>
      <tr>
      <td style="vertical-align: top">Sélectionner votre couleur préféré:</td>
      <td>
        <select name="lstColor" size=5>
       </select>
      </td>
      </tr>
     </table>
       <input type="button" id="poButtonEnvoyer" value="Envoyer" />
     </form>           
    </body>
    </html>
     
    <script language="javascript">
     
    window.onload = pvRemplir;
    document.forms[0].poButtonEnvoyer.onclick = pvEnvoyer;
    var gsResultat;
     
    //Initialisation des variables de base
    gsResultat = "";
     
    function pvRemplir()
    {
        var ioOption;
        var isValeur;
        var iiIndex;
     
        iaTableauValeur = new Array("bleu", "rouge", "jaune", "vert");
     
        document.forms[0].txtNom.value="toto";
        document.forms[0].txtPrenom.value="titi";
        document.forms[0].txtDateNaissance.value="14/07/1995";
     
     
        for (iiIndex=0; iiIndex < iaTableauValeur.length; iiIndex++)
        {
            isValeur =  iaTableauValeur[iiIndex];
            ioOption = new Option(isValeur);
     
            document.forms[0].lstColor.add(ioOption);
        }     
     
        document.forms[0].optMetier.selectedIndex =-1;
     
    }            
     
    function pvEnvoyer()
    {
       if (pbControleSaisie() == true)
       {
           alert("Les données saisies et contrôlées sont : \n" +  gsResultat);
       }
    }
     
    function pbControleSaisie()
    {     
         var iiElementIndex;
         var isLibelle;
         var ioObjet;
     
     
         for (iiIndex=0; iiIndex < document.forms[0].length-1; iiIndex++)
         {
             isValeur = document.forms[0].elements[iiIndex].value;
             isName = document.forms[0].elements[iiIndex].name;
     
             if (isName.substring(0,3) == "opt" || isName.substring(0,3) == "lst" || isName.substring(0,3) == "txt")
             {  
                   if (isName.substring(0,3) != "opt" && isName.substring(0,3) != "lst")
                   {     
                      isValeur  = document.forms[0].elements[iiIndex].value ;
                   }
                   else
                   {   
                      iiSelectedOption =  document.forms[0].elements[iiIndex].options.selectedIndex;
                      if (iiSelectedOption != -1)
                      {
                         isValeur= document.forms[0].elements[iiIndex].options[iiSelectedOption].text; 
                      }
                      else
                      {
                         isValeur = "";
                      }                                
                   }          
     
                   if (isValeur == "")
                   {  
                      ioObjet = document.getElementsByName(isName);
                      iiElementIndex = 
                      isLibelle = iiElementIndex.innerHTML;
     
                      isMessage = "La zone «" + isLibelle + "» n'est pas renseignée\nVeuillez corriger, SVP.";
                      alert(isMessage);
                      document.forms[0].elements[iiIndex].focus();
                      return false;
                   }
                   else
                   {
                      gsResultat += isValeur + "\n";
                   }
             }
        }    
     
        //Si on arrive ici, c'est que tout est OK 
        return true;
     
    }
    </script>
    et merci encore une fois

Discussions similaires

  1. Enregistrer un tableau en object en JavaScript
    Par prilix dans le forum Général JavaScript
    Réponses: 9
    Dernier message: 26/03/2015, 17h08
  2. Object Oriented Javascript
    Par stitox dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 19/02/2012, 17h18
  3. Réponses: 2
    Dernier message: 14/08/2011, 15h37
  4. Transtypage Object->Derivé d'object
    Par anykeyh dans le forum Collection et Stream
    Réponses: 7
    Dernier message: 26/10/2005, 14h39

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