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 �clair�
    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
    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 chevronn� 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
    Par d�faut
    Initialises tu les variables que tu utilises genre var x6 = 0;

  3. #3
    Membre �clair�
    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
    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 chevronn� 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
    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 �clair�
    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
    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 chevronn� 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
    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 �clair�
    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
    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 chevronn� 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
    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 �clair�
    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
    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 chevronn� 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
    Par d�faut
    Simplifie to code au max et poste le

  11. #11
    Membre �clair�
    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
    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 chevronn� 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
    Par d�faut
    Sur ma machine je n'ai pas install� WAMP. Peux tu poster simplement le source html

  13. #13
    Membre �clair�
    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
    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 chevronn� 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
    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 chevronn� 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
    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