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.

is this a JS problem

Discussion in 'JavaScript' started by ataloss, Jul 19, 2014.

  1. #1
    Hi guys, my programming is a pasttime but still important to me. The following
    code is a payment doc. allowing partial payments. Balances are put in "prevbal"
    field. Complete payments get a "P" code. When the paidamt is keyed in, the
    current date is autoinserted. If a recurring debt the amtdue stays the same.
    If it is, the amtdue is calculated. I'm unsure if the failure is in the
    javascript or not?

    ==============================================================================
    The javascript follows:
    function $_(IDS) { return document.getElementById(IDS); }
    function calculate_paid()
      {
      var status = document.getElementById("status");
      var pd = document.getElementById("pd");
      var payec = document.getElementById("payec"); 
      var paidamt = document.getElementById("paidamt");
      var amtdue = document.getElementById("amtdue");
      var prevbal = document.getElementById("prevbal");
      var shipamt = document.getElementById("shipamt");
    var datepaid = document.getElementById("datepaid");
    
      var dateNow = new Date();
      var dayNow = dateNow.getDate();
      var datePaid = (dateNow.getMonth()+1)+"-"+dateNow.getDate()+"-"+dateNow.getFullYear();
    datepaid.value = datePaid;
    var owed.value == parseFloat(amtdue.value) + parseFloat(shipamt.value) +  parseFloat(prevbal.value) - parseFloat(paidamt.value);
    if(status=="N"){amtdue.value = owed.value;}
    if(owed=="0.00") { pd.value = "P"; shipamt="0.00", prevbal="0.00";}
      }
    Code (markup):
    ========================================================================

    <td><input type='text' readonly size=15 name='acctno' value='" . $row['acctno'] . "' ></td>
    <td><input type='text' readonly size=25 name='bname' value='" . $row['bname'] . "'></td>
    <td><input type='text' readonly size=25 name='purpose' value='" . $row['purpose'] . "'></td>
    <td><input type='text' size=7 id='paidamt' name='paidamt' value='" . $row['paidamt'] ."'
      onblur='calculate_paid(this)'></td>
    <td><input type='text' size=7 id='amtdue' name='amtdue' value='" . $row['amtdue'] . "' ></td>
    <td><input type='text' size=7 id='prevbal' name='amtdue' value='" . $row['prevbal'] . "' ></td>
    <td><input type='text' size=10 id='datepaid' name='datepaid' value='" . $row['datepaid'] . "' ></td>
    <td><input type='text' size=3 id='pd' name='pd' value='" . $row['pd'] . "' ></td><br />
    <td><input type='submit' name='update' value='Make Payment' />
    </tr>";
      }
    echo "</table>
    <input type='submit' name='update' value='Update Record' />
    </form>";
      }
    else{echo "invalid entry<br />Select another?<br />";}
      }
    if(!empty($_POST["update"]))
      {
      $sql = "UPDATE oocust SET 
      amtdue = '" . mysql_real_escape_string($_POST['amtdue']) . "',
      paidamt = '" . mysql_real_escape_string($_POST['paidamt']) . "',
    datepaid = '" . mysql_real_escape_string($_POST['datepaid']) . "',
      pd = '" . mysql_real_escape_string($_POST['pd']) . "'
      WHERE acctno='".$_POST['acctno']."'";
    mysql_query($sql) or die(mysql_error());
    echo "Success!";
      }
      ?>
    <form method="post" action="#"><br />
    <input type="text" name="acctno"/> <p>
    <input type="submit" name="submit" value="Select"/>
    </form></body></html>
    Code (markup):

     
    Last edited by a moderator: Jul 19, 2014
    ataloss, Jul 19, 2014 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,991
    Likes Received:
    4,574
    Best Answers:
    124
    Trophy Points:
    665
    #2
    can you set up a jsfiddle for us to look at please
     
    sarahk, Jul 19, 2014 IP