SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    0 Post(s)
    0 Thread(s)

    [Code Review] Old javascript to calculate time


    I try to speak english... So, i have a web page like this. It calculate time for a database. The javascript is "old" and i would like to change it.

    Yes, i'm not a specialist...
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <script type="text/javascript">
    function reportdebutst() {
    debutsth = document.formulaire.champ56.value;
    debutstm = document.formulaire.champ57.value;
    document.formulaire.debut.value = debutsth +":"+ debutstm;
    function reportfinst() {
    finsth = document.formulaire.champ52.value;
    finstm = document.formulaire.champ53.value;
    document.formulaire.fin.value = finsth +":"+ finstm;
    function calcul_sousdeux()
    i= document.formulaire.champ51.value;
    j= document.formulaire.champ52.value;
    k= document.formulaire.champ53.value;
    l= document.formulaire.champ54.value;
    m= document.formulaire.champ55.value;
    n= document.formulaire.champ56.value;
    o= document.formulaire.champ57.value;
    p= document.formulaire.champ58.value;
    nbredeux= (((i*86400)+(j*3600)+(k*60)+(l*1))-((m*86400)+(n*3600)+(o*60)+(p*1)))
    if (nbredeux<0)
    alert("L'heure de début doit être inférieure à l'heure de fin !");
    nbre5= Math.floor(nbredeux/86400)
    nbre6= Math.floor((nbredeux-(nbre5*86400))/3600)
    nbre7= Math.floor(((nbredeux-((nbre5*86400)+(nbre6*3600))))/60)
    nbre8= (nbredeux-((nbre5*86400)+(nbre6*3600)+(nbre7*60)))
    document.formulaire.champ59.value= nbre5
    document.formulaire.champ60.value= nbre6
    document.formulaire.champ61.value= nbre7
    document.formulaire.duree.value= nbre8
    function calcul2()
    nbre5= document.formulaire.champ59.value;
    nbre6= document.formulaire.champ60.value;
    nbre7= document.formulaire.champ61.value;
    nbre8= document.formulaire.duree.value;
    résultat= ((nbre5*86400)+(nbre6*3600)+(nbre7*60)+(nbre8*1))/60
    document.formulaire.champ59.value= 0;
    document.formulaire.champ60.value= 0;
    document.formulaire.champ61.value= 0;
    document.formulaire.duree.value= résultat;
    <form action="#" method="post" name="formulaire" id="formulaire" onsubmit="return verification(formulaire)">
    <label class = "text" for = "start">He worked from :</label>
    <input type="hidden" size="2" name="champ54" readonly="readonly" />
    <input type="hidden" size="2" name="champ55" readonly="readonly" />
    <select name="champ56">
            <option value="08">08&nbsp;</option>
            <option value="09">09&nbsp;</option>
            <option value="17">17&nbsp;</option>
    <select name="champ57">
    <option value="00">00&nbsp;</option>
    <option value="01">01&nbsp;</option>
    <option value="59">59&nbsp;</option>
    <input type="hidden" name="champ58" readonly="readonly" />
    to <input type="hidden" name="champ51" readonly="readonly" />
    <select name="champ52">
           <option value="08">08&nbsp;</option>
            <option value="09">09&nbsp;</option>
            <option value="17">17&nbsp;</option>
    <select name="champ53">
    <option value="00">00&nbsp;</option>
    <option value="01">01&nbsp;</option>
    <option value="02">02&nbsp;</option>
    <option value="59">59&nbsp;</option>
    <input type="hidden" size="2" name="champ59" readonly="readonly" />
    <input type="hidden" size="2" name="champ60" readonly="readonly" />
    <input type="hidden" size="2" name="champ61" readonly="readonly" />
    <input type="submit" value="Valider" onclick="calcul_sousdeux(),reportdebutst(),reportfinst(),calcul2()"  />
    It works but i would like to change it. (It's very long)

    Can you help me ?

    Thank you very much

    table request result
    Attached Images Attached Images


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts