1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Math with Javascript

Discussion in 'JavaScript' started by BWDOW, Dec 16, 2007.

  1. #1
    I have a problem with Javascript. I want to make calculation with JS but not avaible. Can you please look to my code whats wrong with it. I want to show all total amount at "toplamtutar" and calculate each of the "tutar" values.
    
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
    
    <script language="JavaScript">
    function tutartopla()
    {
    var tutar1,tutar2,tutar3,tutar4,tutar5
    t1 = document.form1.tutar1.value
    t2 = document.form1.tutar2.value
    t3 = document.form1.tutar3.value
    t4 = document.form1.tutar4.value
    t5 = document.form1.tutar5.value
    document.form1.toplamtutar.value = eval(t1)+eval(t2)+eval(t3)+eval(t4)+eval(t5)
    }
    </script>
    
    <script language="JavaScript">
    function toplam() {
    var fyt,adt,ttr
    fyt = document.form1.fiyat1.value;
    adt = document.form1.adet1.value;
    ttr1 = fyt1 * adt1;
    document.form1.tutar1.value  = Math.round(ttr1*100)/100;
    document.form1.tutar1.value  = adt;
    }
    </script>
    
    <title>Untitled Document</title>
    </head>
    
    <body>
      <table border="1">
      <tbody><tr>
      <td>group</td>
      <td>product</td>
        <td>price</td>
        <td>quantity</td>
    
        <td>total</td>
      </tr>
      
        <tr>
          <td width="25"><select kt_onchange_attached="true" name="select1" id="select1">
                    <option value="1">Alkolluler</option>
                    <option value="2">Alkolsuzler</option>
                  </select></td>
    
          <td width="30"><select kt_onchange_attached="true" wdg:subtype="DependentDropdown" name="select2" id="select2" wdg:type="widget" wdg:recordset="RecSTOK" wdg:displayfield="ADI" wdg:valuefield="KODU" wdg:fkey="GRUP" wdg:triggerobject="select1">
          <option value="8">Sarap</option><option value="7">BACARDi</option><option value="11">Cin Tonik</option><option value="9">Raki</option><option value="12">Santa Maria</option><option value="10">Votka</option></select></td>
          <td width="7"><input name="fiyat1" type="text" id="fiyat1" value="25" size="6" readonly="readonly" wdg:subtype="N1DependentField" wdg:type="widget" wdg:recordset="RecSTOK" wdg:valuefield="SATISFIYATI" wdg:pkey="KODU" wdg:triggerobject="select2"></td>
          <td width="8">
            <input name="adet1" id="adet1" size="6" onkeydown="toplam();" type="text">      </td>
    
          <td width="10">
            <input name="tutar1" id="tutar1" size="13" value="0" onchange="'tutartopla()" type="text">      </td>
        </tr>
        <tr>
          <td><select kt_onchange_attached="true" name="select3" id="select3">
                    <option value="1">Alkolluler</option>
                    <option value="2">Alkolsuzler</option>
    
                  </select></td>
          <td><select kt_onchange_attached="true" wdg:subtype="DependentDropdown" name="select4" id="select4" wdg:type="widget" wdg:recordset="RecSTOK" wdg:displayfield="ADI" wdg:valuefield="KODU" wdg:fkey="GRUP" wdg:triggerobject="select3">
          <option value="2">KOLA</option><option value="6">KOLA DIET</option><option value="3">SÜT</option><option value="4">Visne Suyu</option></select></td>
          <td><input name="fiyat2" type="text" id="fiyat2" value="12.4" size="6" readonly="readonly" wdg:subtype="N1DependentField" wdg:type="widget" wdg:recordset="RecSTOK" wdg:valuefield="SATISFIYATI" wdg:pkey="KODU" wdg:triggerobject="select4"></td>
          <td><input name="adet2" id="adet2" size="6" type="text"></td>
          <td><input name="tutar2" id="tutar2" size="13" value="0" onchange="'tutartopla()" type="text"></td>
        </tr>
        <tr>
          <td><select kt_onchange_attached="true" name="select5" id="select5">
                    <option value="1">Alkolluler</option>
                    <option value="2">Alkolsuzler</option>
                  </select></td>
          <td><select kt_onchange_attached="true" wdg:subtype="DependentDropdown" name="select6" id="select6" wdg:type="widget" wdg:recordset="RecSTOK" wdg:displayfield="ADI" wdg:valuefield="KODU" wdg:fkey="GRUP" wdg:triggerobject="select5">
          <option value="8">Sarap</option><option value="7">BACARDi</option><option value="11">Cin Tonik</option><option value="9">Raki</option><option value="12">Santa Maria</option><option value="10">Votka</option></select></td>
    
          <td><input name="fiyat3" type="text" id="fiyat3" value="4.8" size="6" readonly="readonly" wdg:subtype="N1DependentField" wdg:type="widget" wdg:recordset="RecSTOK" wdg:valuefield="SATISFIYATI" wdg:pkey="KODU" wdg:triggerobject="select6"></td>
          <td><input name="adet3" id="adet3" size="6" type="text"></td>
          <td><input name="tutar3" id="tutar3" size="13" value="0" onchange="'tutartopla()" type="text"></td>
        </tr>
        <tr>
          <td colspan="4">total</td>
          <td><label>
            <input name="toplamtutar" id="toplamtutar" type="text">
          </label></td>
        </tr>
      </tbody></table>
    
    </body>
    </html>
    
    
    HTML:

     
    BWDOW, Dec 16, 2007 IP
  2. thinlight

    thinlight Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There must be an element with id attribute set to "form1". Besides, the way "document.form1" only works in IE. You should use "document.getElementById('form1')" for better compatibility :)
     
    thinlight, Dec 17, 2007 IP
  3. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Why are you using eval on the input values?
     
    MMJ, Dec 17, 2007 IP