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 :

Je n'arrive pas a faire un controle dans un calcul javascript


Sujet :

JavaScript

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

    Informations forums :
    Inscription : Décembre 2005
    Messages : 329
    Points : 126
    Points
    126
    Par défaut Je n'arrive pas a faire un controle dans un calcul javascript
    Bonjour

    J'ai fais une fonction mathématique en javascript qui fonctionne. Mais je voudrais faire à l'intérieur de cette fonction caclul un fonction de controle.

    Je voudrais mettre ceci
    if (x6<x3){x6=x3}{....on affiche le calcul}
    met dans le javascript je n'arrive pas à mettre une fonction de ce genre.

    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
    <?php
    session_start();
    $qte_b = 1;
    ?>
    <html>
    <head>
    <SCRIPT LANGUAGE="javascript">
    function calcul_pr_var(f){var y1=f.qte_f.value;
                             if (isNaN(y1)) {alert("Prix unitaire incorrect");
    						 f.qte_f.value="";
    						 f.pr_var.value="";
    						 f.qte_f.focus();
    						 return;}
    						 var y2=f.qte.value;
    						 if (isNaN(y2)) {alert("Prix unitaire incorrect");
    						 f.qte.value="";
    						 f.pr_var.value="";
    						 f_qte_f.focus();
    						 return;}
                             var x1=f.pr_uni.value;
                                if (isNaN(x1)) {alert("Prix unitaire incorrect");
                                f.pr_uni.value="";
                                f.pr_var.value="";
                                f.pr_uni.focus();
                                return;}
                                var x2=f.pr_max.value;
                                if (isNaN(x2)) {alert("Prix maximum incorrect");
                                f.pr_max.value="";
                                f.pr_var.value="";
                                f.pr_max.focus();
                                return;}
    							var x3=f.qte_b.value;
    							if (isNaN(x3)) {alert("Prix maximum incorrect");
                                f.qte_b.value="";
                                f.pr_var.value="";
                                f.qte_b.focus();
                                return;}
    							var x4=f.qte_max.value;
    							if (isNaN(x4)) {alert("Prix maximum incorrect");
                                f.qte_max.value="";
                                f.pr_var.value="";
                                f.qte_max.focus();
                                return;}
                                var x6=Math.abs((parseFloat(x1)-(parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))+(((parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))*(parseFloat(y1)+parseFloat(y2))));
                                f.pr_var.value=x6;
    							if (x6<x3){x6=x3;}}
    </SCRIPT>
    </head>
    <body>
    <form>
    <table border="1" align="center">
    <tr>
    <td colspan="2" align="center"><b>Calcul quantité totale</b></td>
    </tr>
    <tr>
    <td><b>Quantité F</b></td>
    <td><input type="text" name="qte_f" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité T</b></td>
    <td><input type="text" name="qte" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><b>Prix variant</b></td>
    </tr>
    <td><b>Prix unitaire</b></td>
    <td><input type="text" name="pr_uni" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Prix minimum</b></td>
    <td><input type="text" name="pr_max" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité de Base</b></td>
    <td><input type="text" disabled=disabled name="qte_b" size="10" value="<?php echo $qte_b;?>" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité maximale</b></td>
    <td><input type="text" name="qte_max" size="10" value="" onKeyUp="calcul_pr_var(this.form);"/></td>
    </tr>
    <tr>
    <td><b>Prix Variant</b></td>
    <td><input type="text" name="pr_var" size="10" value="" readonly="readonly" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    J'ai du mal en javascript pouvez vous m'aider ?

  2. #2
    Membre averti Avatar de supernova
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 415
    Points
    415
    Par défaut
    Initialises tu les variables que tu utilises genre var x6 = 0;

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

    Informations forums :
    Inscription : Décembre 2005
    Messages : 329
    Points : 126
    Points
    126
    Par défaut Rep
    désole je comprends pas!

    J'ai fais cela aussi mais cela ne fonctionne pas

    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
    <SCRIPT LANGUAGE="javascript">
    function calcul_pr_var(f){var y1=f.qte_f.value;
                             if (isNaN(y1)) {alert("Prix unitaire incorrect");
    						 f.qte_f.value="";
    						 f.pr_var.value="";
    						 f.qte_f.focus();
    						 return;}
    						 var y2=f.qte.value;
    						 if (isNaN(y2)) {alert("Prix unitaire incorrect");
    						 f.qte.value="";
    						 f.pr_var.value="";
    						 f_qte_f.focus();
    						 return;}
                             var x1=f.pr_uni.value;
                                if (isNaN(x1)) {alert("Prix unitaire incorrect");
                                f.pr_uni.value="";
                                f.pr_var.value="";
                                f.pr_uni.focus();
                                return;}
                                var x2=f.pr_max.value;
                                if (isNaN(x2)) {alert("Prix maximum incorrect");
                                f.pr_max.value="";
                                f.pr_var.value="";
                                f.pr_max.focus();
                                return;}
    							var x3=f.qte_b.value;
    							if (isNaN(x3)) {alert("Prix maximum incorrect");
                                f.qte_b.value="";
                                f.pr_var.value="";
                                f.qte_b.focus();
                                return;}
    							var x4=f.qte_max.value;
    							if (isNaN(x4)) {alert("Prix maximum incorrect");
                                f.qte_max.value="";
                                f.pr_var.value="";
                                f.qte_max.focus();
                                return;}
                                var x6=Math.abs((parseFloat(x1)-(parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))+(((parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))*(parseFloat(y1)+parseFloat(y2))));
    							if (var x6<x3){f.pr_var.value=x3;}
    							f.pr_var_value=x6;}
    </SCRIPT>

  4. #4
    Membre averti Avatar de supernova
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 415
    Points
    415
    Par défaut
    Je dis simplement que si tu déclares une variable par var maVar ; c'est plus fiable de l'initialiser avec une valeur à 0 au début pour être sûr que Javascript la traite comme un entier. Il n'y a pas de typage en Javascript.

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

    Informations forums :
    Inscription : Décembre 2005
    Messages : 329
    Points : 126
    Points
    126
    Par défaut
    je t explique
    J'ai un formulaire ou je rentre les données.
    Quantité f : 50
    Quantité t : 50
    Prix unitaire : 100
    Prix minimum : 40
    Quantité de base : 1
    Quantité Maximale : 200
    Prix variant: 70,15 obtenu par le calcul.
    Si une personne a mis un seuil minimum de 40 (prix minimum). Si la quantité qui est de 100 dépasse les 200. Le calcul va afficher un prix inférieur à 40. A ce moment la je voudrais que quelque soit le prix variant calculé inférieur à 40, il affiche le prix minimum 40.
    c'est un genre de if (x6 < x3) { x6=x3}{sinon affiche le x6 car il est superieur x3.

  6. #6
    Membre averti Avatar de supernova
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 415
    Points
    415
    Par défaut
    Teste cette page :

    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
    <html>
    <head>
    <title>Contrôle sur valeurs</title>
    <script language="Javascript">
     function controle(f) {
     
     	if (parseInt(f.pm.value) > 40 || parseInt(f.pm.value) < 10) {
     
     		document.forms["form1"].pm.value="40";
     
     	}
     }
    </script>
    </head>
    <body>
    <form name="form1">
     
    Prix minimum : <input type="text" name="pm"><br>
     
    <input type="button" name="bt1" value="Calcul" onClick="Javascript: controle(this.form);">
    </form>
    </body>
    </html>

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

    Informations forums :
    Inscription : Décembre 2005
    Messages : 329
    Points : 126
    Points
    126
    Par défaut Rep
    c'est ça, j'ai tenter d'utiliser ton code dans ma fonction calcul mais cela ne fonctionne pas. Est que tu peux me corriger ce qui est en rouge.

    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
    <?php
    session_start();
    $qte_b = 1;
    ?>
    <html>
    <head>
    <SCRIPT LANGUAGE="javascript">
    function calcul_pr_var(f){var y1=f.qte_f.value;
                             if (isNaN(y1)) {alert("Prix unitaire incorrect");
    						 f.qte_f.value="";
    						 f.pr_var.value="";
    						 f.qte_f.focus();
    						 return;}
    						 var y2=f.qte.value;
    						 if (isNaN(y2)) {alert("Prix unitaire incorrect");
    						 f.qte.value="";
    						 f.pr_var.value="";
    						 f_qte_f.focus();
    						 return;}
                             var x1=f.pr_uni.value;
                                if (isNaN(x1)) {alert("Prix unitaire incorrect");
                                f.pr_uni.value="";
                                f.pr_var.value="";
                                f.pr_uni.focus();
                                return;}
                                var x2=f.pr_min.value;
                                if (isNaN(x2)) {alert("Prix maximum incorrect");
                                f.pr_min.value="";
                                f.pr_var.value="";
                                f.pr_min.focus();
                                return;}
    							var x3=f.qte_b.value;
    							if (isNaN(x3)) {alert("Prix maximum incorrect");
                                f.qte_b.value="";
                                f.pr_var.value="";
                                f.qte_b.focus();
                                return;}
    							var x4=f.qte_max.value;
    							if (isNaN(x4)) {alert("Prix maximum incorrect");
                                f.qte_max.value="";
                                f.pr_var.value="";
                                f.qte_max.focus();
                                return;}
                                var x6=Math.abs((parseFloat(x1)-(parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))+(((parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))*(parseFloat(y1)+parseFloat(y2))));
    							if (parseInt(f.pr_var.value) < (parseInt(f.pr_mini.value)){document.forms["form1"].pr_var.value="(parseInt(f.pr_mini.value))";}
    							else 
    							{f.pr_var.value=x6;}
    </SCRIPT>
    </head>
    <body>
    <form>
    <table border="1" align="center">
    <tr>
    <td colspan="2" align="center"><b>Calcul quantité totale</b></td>
    </tr>
    <tr>
    <td><b>Quantité F</b></td>
    <td><input type="text" name="qte_f" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité T</b></td>
    <td><input type="text" name="qte" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><b>Prix variant</b></td>
    </tr>
    <td><b>Prix unitaire</b></td>
    <td><input type="text" name="pr_uni" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Prix minimum</b></td>
    <td><input type="text" name="pr_min" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité de Base</b></td>
    <td><input type="text" disabled=disabled name="qte_b" size="10" value="<?php echo $qte_b;?>" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité maximale</b></td>
    <td><input type="text" name="qte_max" size="10" value="" onKeyUp="calcul_pr_var(this.form);"/></td>
    </tr>
    <tr>
    <td><b>Prix Variant</b></td>
    <td><input type="text" name="pr_var" size="10" value="" readonly="readonly" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  8. #8
    Membre averti Avatar de supernova
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 415
    Points
    415
    Par défaut
    if ((parseInt(f.pr_var.value)) < (parseInt(f.pr_mini.value)){

    document.forms["form1"].pr_var.value=f.pr_mini.value;
    }

    else
    {f.pr_var.value="";}

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

    Informations forums :
    Inscription : Décembre 2005
    Messages : 329
    Points : 126
    Points
    126
    Par défaut
    Et mince le calcul ne se fait plus

    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
    <?php
    session_start();
    $qte_b = 1;
    ?>
    <html>
    <head>
    <SCRIPT LANGUAGE="javascript">
    function calcul_pr_var(f){var y1=f.qte_f.value;
                             if (isNaN(y1)) {alert("Prix unitaire incorrect");
    						 f.qte_f.value="";
    						 f.pr_var.value="";
    						 f.qte_f.focus();
    						 return;}
    						 var y2=f.qte.value;
    						 if (isNaN(y2)) {alert("Prix unitaire incorrect");
    						 f.qte.value="";
    						 f.pr_var.value="";
    						 f_qte_f.focus();
    						 return;}
                             var x1=f.pr_uni.value;
                                if (isNaN(x1)) {alert("Prix unitaire incorrect");
                                f.pr_uni.value="";
                                f.pr_var.value="";
                                f.pr_uni.focus();
                                return;}
                                var x2=f.pr_min.value;
                                if (isNaN(x2)) {alert("Prix maximum incorrect");
                                f.pr_min.value="";
                                f.pr_var.value="";
                                f.pr_min.focus();
                                return;}
    							var x3=f.qte_b.value;
    							if (isNaN(x3)) {alert("Prix maximum incorrect");
                                f.qte_b.value="";
                                f.pr_var.value="";
                                f.qte_b.focus();
                                return;}
    							var x4=f.qte_max.value;
    							if (isNaN(x4)) {alert("Prix maximum incorrect");
                                f.qte_max.value="";
                                f.pr_var.value="";
                                f.qte_max.focus();
                                return;}
                                var x6=Math.abs((parseFloat(x1)-(parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))+(((parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))*(parseFloat(y1)+parseFloat(y2))));
    							if ((parseInt(f.pr_var.value)) < (parseInt(f.pr_mini.value)){
                                document.forms["form1"].pr_var.value=f.pr_mini.value;}
                                else{f.pr_var.value="";}
    </SCRIPT>
    </head>
    <body>
    <form>
    <table border="1" align="center">
    <tr>
    <td colspan="2" align="center"><b>Calcul quantité totale</b></td>
    </tr>
    <tr>
    <td><b>Quantité F</b></td>
    <td><input type="text" name="qte_f" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité T</b></td>
    <td><input type="text" name="qte" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><b>Prix variant</b></td>
    </tr>
    <td><b>Prix unitaire</b></td>
    <td><input type="text" name="pr_uni" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Prix minimum</b></td>
    <td><input type="text" name="pr_min" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité de Base</b></td>
    <td><input type="text" disabled=disabled name="qte_b" size="10" value="<?php echo $qte_b;?>" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité maximale</b></td>
    <td><input type="text" name="qte_max" size="10" value="" onKeyUp="calcul_pr_var(this.form);"/></td>
    </tr>
    <tr>
    <td><b>Prix Variant</b></td>
    <td><input type="text" name="pr_var" size="10" value="" readonly="readonly" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  10. #10
    Membre averti Avatar de supernova
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 415
    Points
    415
    Par défaut
    Simplifie to code au max et poste le

  11. #11
    Membre habitué
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    329
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 329
    Points : 126
    Points
    126
    Par défaut rep
    voici le code qui marche mais sans structure de controle que je veux faire tu peux faire un copier coller dans une page 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
     
    <?php
    session_start();
    $qte_b = 1;
    ?>
    <html>
    <head>
    <SCRIPT LANGUAGE="javascript">
    function calcul_pr_var(f){var y1=f.qte_f.value;
                             if (isNaN(y1)) {alert("Prix unitaire incorrect");
    						 f.qte_f.value="";
    						 f.pr_var.value="";
    						 f.qte_f.focus();
    						 return;}
    						 var y2=f.qte.value;
    						 if (isNaN(y2)) {alert("Prix unitaire incorrect");
    						 f.qte.value="";
    						 f.pr_var.value="";
    						 f_qte_f.focus();
    						 return;}
                             var x1=f.pr_uni.value;
                                if (isNaN(x1)) {alert("Prix unitaire incorrect");
                                f.pr_uni.value="";
                                f.pr_var.value="";
                                f.pr_uni.focus();
                                return;}
                                var x2=f.pr_min.value;
                                if (isNaN(x2)) {alert("Prix maximum incorrect");
                                f.pr_min.value="";
                                f.pr_var.value="";
                                f.pr_min.focus();
                                return;}
    							var x3=f.qte_b.value;
    							if (isNaN(x3)) {alert("Prix maximum incorrect");
                                f.qte_b.value="";
                                f.pr_var.value="";
                                f.qte_b.focus();
                                return;}
    							var x4=f.qte_max.value;
    							if (isNaN(x4)) {alert("Prix maximum incorrect");
                                f.qte_max.value="";
                                f.pr_var.value="";
                                f.qte_max.focus();
                                return;}
                                var x6=Math.abs((parseFloat(x1)-(parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))+(((parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))*(parseFloat(y1)+parseFloat(y2))));
                                f.pr_var.value=x6;}
     
    </SCRIPT>
    </head>
    <body>
    <form>
    <table border="1" align="center">
    <tr>
    <td colspan="2" align="center"><b>Calcul quantité totale</b></td>
    </tr>
    <tr>
    <td><b>Quantité F</b></td>
    <td><input type="text" name="qte_f" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité T</b></td>
    <td><input type="text" name="qte" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><b>Prix variant</b></td>
    </tr>
    <td><b>Prix unitaire</b></td>
    <td><input type="text" name="pr_uni" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Prix minimum</b></td>
    <td><input type="text" name="pr_min" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité de Base</b></td>
    <td><input type="text" disabled=disabled name="qte_b" size="10" value="<?php echo $qte_b;?>" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité maximale</b></td>
    <td><input type="text" name="qte_max" size="10" value="" onKeyUp="calcul_pr_var(this.form);"/></td>
    </tr>
    <tr>
    <td><b>Prix Variant</b></td>
    <td><input type="text" name="pr_var" size="10" value="" readonly="readonly" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  12. #12
    Membre averti Avatar de supernova
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 415
    Points
    415
    Par défaut
    Sur ma machine je n'ai pas installé WAMP. Peux tu poster simplement le source html

  13. #13
    Membre habitué
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    329
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 329
    Points : 126
    Points
    126
    Par défaut rep
    voila en html


    calcul_pr_var.htm
    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
     
    <html>
    <head>
    <SCRIPT LANGUAGE="javascript">
    function calcul_pr_var(f){var y1=f.qte_f.value;
                             if (isNaN(y1)) {alert("Prix unitaire incorrect");
    						 f.qte_f.value="";
    						 f.pr_var.value="";
    						 f.qte_f.focus();
    						 return;}
    						 var y2=f.qte.value;
    						 if (isNaN(y2)) {alert("Prix unitaire incorrect");
    						 f.qte.value="";
    						 f.pr_var.value="";
    						 f_qte_f.focus();
    						 return;}
                             var x1=f.pr_uni.value;
                             if (isNaN(x1)) {alert("Prix unitaire incorrect");
                             f.pr_uni.value="";
                             f.pr_var.value="";
                             f.pr_uni.focus();
                             return;}
                             var x2=f.pr_min.value;
                             if (isNaN(x2)) {alert("Prix maximum incorrect");
                             f.pr_min.value="";
                             f.pr_var.value="";
                             f.pr_min.focus();
                             return;}
    						 var x3=f.qte_b.value;
    						 if (isNaN(x3)) {alert("Prix maximum incorrect");
                             f.qte_b.value="";
                             f.pr_var.value="";
                             f.qte_b.focus();
                             return;}
    					     var x4=f.qte_max.value;
    					     if (isNaN(x4)) {alert("Prix maximum incorrect");
                             f.qte_max.value="";
                             f.pr_var.value="";
                             f.qte_max.focus();
                             return;}
                             var x6=Math.abs((parseFloat(x1)-(parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))+(((parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))*(parseFloat(y1)+parseFloat(y2))));
                                f.pr_var.value=x6;}				
    </SCRIPT>
    </head>
    <body>
    <form>
    <table border="1" align="center">
    <tr>
    <td colspan="2" align="center"><b>Calcul quantité totale</b></td>
    </tr>
    <tr>
    <td><b>Quantité F</b></td>
    <td><input type="text" name="qte_f" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité T</b></td>
    <td><input type="text" name="qte" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><b>Prix variant</b></td>
    </tr>
    <td><b>Prix unitaire</b></td>
    <td><input type="text" name="pr_uni" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Prix minimum</b></td>
    <td><input type="text" name="pr_min" size="10" value="" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité de Base</b></td>
    <td><input type="text" disabled=disabled name="qte_b" size="10" value="1" onKeyUp="calcul_pr_var(this.form);" /></td>
    </tr>
    <tr>
    <td><b>Quantité maximale</b></td>
    <td><input type="text" name="qte_max" size="10" value="" onKeyUp="calcul_pr_var(this.form);"/></td>
    </tr>
    <tr>
    <td><b>Prix Variant</b></td>
    <td><input type="text" name="pr_var" size="10" value="" readonly="readonly" onKeyUp="calcul_pr_var(this.form);controle(this.form);" /></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  14. #14
    Membre averti Avatar de supernova
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 415
    Points
    415
    Par défaut
    Tu ne submit pas ton formulaire ? KeyUp te permet de saisir qu'un seul caractère pour déclencher l'évenement.

  15. #15
    Membre averti Avatar de supernova
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 415
    Points
    415
    Par défaut
    Je pense qu'une valeur n'est pas initialisée ou alors un problème de parenthèse ; l'exemple ci-dessous fonctionne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     
    	        x1 = "10";
    	        x2 = "25";
    	        x3 = "46";
    	        x4 = "64";
    	        y1 = "22";
    	        y2 = "12";
                             //var x6=Math.abs((parseFloat(x1)-(parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))+(((parseFloat(x1)-parseFloat(x2))/(parseFloat(x3)-parseFloat(x4)))*(parseFloat(y1)+parseFloat(y2))));
                             x6 = Math.abs((parseFloat(x1) - parseFloat(x1)-parseFloat(x2)) / (parseFloat(x3)-parseFloat(x4)) + ((parseFloat(x1)-parseFloat(x2))/ (parseFloat(x3)-parseFloat(x4))) * (parseFloat(y1)+parseFloat(y2)));
                                f.pr_var.value=x6;

Discussions similaires

  1. Réponses: 8
    Dernier message: 05/11/2010, 21h29
  2. [C#] SQL - je n'arrives pas a faire ma requete
    Par Cazaux-Moutou-Philippe dans le forum Windows Forms
    Réponses: 5
    Dernier message: 06/07/2006, 14h43
  3. Je n'arrive pas à faire des boucles dans un répertoire
    Par padodanle51 dans le forum Linux
    Réponses: 4
    Dernier message: 04/05/2006, 18h04
  4. Réponses: 6
    Dernier message: 18/04/2006, 13h11
  5. [réplication]N'arrive pas à le faire marcher!!!!
    Par mohamed dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 27/03/2006, 14h29

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