Problème en php

Bonjour,
J'ai une page .php
les sélects sont remplient a l'aide de la base de donner MySQL et s'affiche normale.
mais la page n'exécute pas le fichier JavaScript qui permet le calcul.
Voici le code:
<HTML>
<head>
<script type="text/javascript" src="calcule.js"> </script>
</head>
<BODY background="fond2.jpg">
<?php
$host="localhost";
$user="root";
$pass="";
$name="bp";
mysql_connect ($host,$user,$pass) or die ("erreur de connexion");
mysql_select_db($name) or die (mysql_error());
?>
<div style="position: absolute; z-index: 1; left: 250px; top: 20px" id="couche1">
<form name="f2" method='POST' onSubmit="return calcule()">
<table align="left" Border="4" bgcolor="#96D7F5" bordercolorlight="#0000FF" >
<tr > <td colspan="3"> <center> <H2> <strong>Calcul Bande Passante (VoIP)</strong></H2> </center> </td> </tr>
<TR><TD><center>Taille</center></TD> <TD colspan="2" > <center> <Select name="taille" > <option> Taille de l'echantillon </option> <option value="5"> 5 </option><option value="10"> 10 </option> <option value="20"> 20 </option> <option value="30"> 30 </option> <option value="40"> 40 </option> </select> ms </center> </TD></TR>
<TR><TD > <center> Codec </center></TD> <TD> <center> <SELECT name="Codec" id="Codec"> <option> Codec </option> <option value="8"> G.711 </option> <option value="1"> G.729 </option>
<?php
$sql = 'SELECT * FROM 'Codec'';
$SqlStr = mysql_query($sql);
while ($rang=mysql_fetch_array($SqlStr))
{
$nom = $rang['Nom'];
$mos= $rang['mos'];
$coif= $rang['coif'];
$deb=$mos*$coif;
echo "<option value='$deb'> $nom </option>";
}
?>
</select> </center> </TD> </TR>
<TR><TD > <center> Mos</center></TD> <TD colspan="2" ><center><input type="text" name="mos" value="" /> </center></TD></TR>
<tr><center> <TD colspan="3" > <center> <a href="AjoutCodec.html"> <input type="button" value="Ajouter Codec" onClick="AjoutCodec.html" /> </a> </center> </TD> </center></tr>
<TR> <TD ><center>IP</center></TD> <TD colspan="2" ><center> <input type="radio" name="s" value="20" checked> IPv4 <input type="radio" name="s" value="40"> IPv6 </center></TD></tr>
<TR> <TD ><center> VAD</center></TD><td colspan="2" > <center><input type="text" value="0.7" name="vad"/> </center></TD></tr>
<TR> <td > <center> Protocole L2 </center></td><TD colspan="2" > <center> <Select name="pl2" ><option value="18"> Ethernet Half </option> <option value="22"> Ethernet Half avec Priorite </option> <option value="28"> Ethernet Full </option> <option value="32"> Ethernet Full avec Priorite </option> <option value="8"> PPP</option> <option value="6"> Frame Relay </option></Select> </center></TD></TR>
<tr><center> <TD colspan="3" > <center> <a href="AjoutProtocole.html"> <input type="button" value="Ajouter Protocole Couche 2" onClick="AjoutCodec.html" /> </a> </center> </TD> </center></tr>
<TR> <TD colspan="3"><center> <input type="Submit" value="Calculer" /> <input type="Reset" value="Annuler" /> </center> </TD></TR>
<TR > <TD colspan="3"> <center> <H3> Pour un appel </H3></center> </TD></TR>
<TR > <td > <center> Bande Passante L3</center></td><TD colspan="2" ><input type="Text" name="l3" /> kb/s</TD></TR>
<TR> <td> <center> Bande Passante L2 </center></td><TD colspan="2" ><input type="Text" name="l2" />kb/s </TD></TR>
<TR> <td colspan="3"> <center> <H3> Pour N appels </H3></center> </td></TR>
<TR> <td ><center> N </center></td> <td colspan="2" ><input type="text" name="n" /> </TD></TR>
<TR > <TD colspan="3"><center> <input type="button" value="ReCalculer" onClick="recalcule()" /> </center></TD></TR>
<TR> <td ><center> Bande Passante L3 </center></td><TD colspan="2" > <input type="Text" name="nl3"/> kb/s </TD></TR>
<TR> <td ><center> Bande Passante L2 </center></td><TD colspan="2" > <input type="Text" name="nl2" /> kb/s </TD></TR>
</table>
</form>
</div>
</BODY>
</HTML>

calcule.js
// JavaScript Document
function calcule()
{
//calcule

//declaration des variables & initialisation

var taille=parseInt(document.f2.taille.value);
var codec=parseInt(document.f2.codec.value);
if(document.f2.s[0].checked)
id=20;
if(document.f2.s[1].checked)
id=40;
if(!(document.f2.s[0].checked)&&!(document.f2.s[1].checked))
{
alert("vous devez choisir un ID");document.f2.focus();return false;}
var vad=document.f2.vad.value;
var pl2=document.f2.pl2.value;
//verification

if(isFinite(taille)==false)
{alert("verifier la taille");
document.f2.taille.focus();return false;
}

if(isFinite(codec)==false)
{alert("Verifier le Codec");
document.f2.codec.focus();return false;
}

if(document.f2.codec.selectedIndex+1==8){
var vad=1;
document.f2.codec.focus(); return false;
}
var a=codec*taille;
var a1=a+id+20;
var a2=1000/taille;
var a3=a1*a2;
var a4=a3*vad;
var a5=a4*8;
var a6=a5/1000;

document.f2.l3.value=(a6);
document.f2.l3.focus();

if(document.f2.codec.selectedIndex+1==8){
var vad=1;
}
var b=codec*taille;
var b1=b+id+20+parseInt(pl2);
var b2=1000/taille;
var b3=b1*b2;
var b4=b3*vad;
var b5=b4*8;
var b6=b5/1000;

document.f2.l2.value=(b6);
document.f2.l2.focus(); return false;
}

function recalcule()
{
var n=parseInt(document.f2.n.value);
if (isNaN(n)) {
alert("n est un nombre");
}
var r=(document.f2.l2.value);
var r1=(document.f2.l3.value);
var c=(n*r);

var c1=(n*r1);

document.f2.nl3.value=(c1);
document.f2.nl2.value=(c);
document.f2.nl2.focus(); return false;

}

2 réponses

  1. J'ai pas mes outils avec moi, mais je ne vois nulle part l'appel de tes fonctions; tu ne fais que les deffifir je crois
    1. Je suis un débutant merci de me montrer mes faute.
      NB: quand j'annule le code php des sélects et j'initialise manuellement avec html, le calcul se fait juste.
    2. Je suis sur mon téléphone, je ne peux donc pas te faire ça :/

      Mais en gros, tu définie tes fonctions

      function recalcule() { var n=parseInt(document.f2.n.value); if(isNaN(n)) { alert("n est un nombre"); }

      Mais il faut les appeler :
      Recalcule()
  2. déja fait j'ai appeler la fonction: onSubmit="return calcule()"
    et le fichier js ou se trouve la fonction : <script type="text/javascript" src="calcule.js"> </script>
    Merci mon ami en tt ca