www.webdeveloper.com
Results 1 to 3 of 3

Thread: need help w/onblur

  1. #1
    Join Date
    Apr 2013
    Posts
    73

    need help w/onblur

    I'm trying to use js function to: upon entering "paidamt" change the "amtdue",
    "prevbal",auto-insert the current date(datepaid), change"pd", and increment
    the "checkno". I had this working at one time but memory precludes the use of the
    onblur. The following code displays all values for selected record from database
    and only updates "paidamt". Any help?

    HTML Code:
    echo "<tr>
    <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=5 name='amtdue' value='" . $row['amtdue'] . "' ></td>
    <td><input type='text' size=5 name='prevbal' value='" . $row['prevbal'] . "' ></td>
    <td><input type='text' size=5 name='datepaid' value='" . $row['datepaid'] . "' ></td>
    <td><input type='text' size=5 name='pd' value='" . $row['pd'] . "' ></td>
    <td><input type='text' size=5 name='checkno' value='" . $row['checkno'] . "' ></td>
    </tr>";
    Code:
    function $_(IDS) { return document.getElementById(IDS); }
    function calculate_paid() 
      { 
       var recur = parseInt(document.getElementById("recur").value;
       var pd = parseInt(document.getElementById("pd").value;   
       var shipamt = parseFloat(document.getElementById("shipamt").value;
       var paidamt = parseFloat(document.getElementById("paidamt").value;
       var prevbal = parseFloat(document.getElementById("prevbal").value;
       var amtdue = parseFloat(document.getElementById("amtdue").value;
       var checkno = parseInt(document.getElementById("checkno").value;
       var datepaid = parseFloat(document.getElementById("datepaid").value;
       var dateNow = new Date();
       var dayNow = dateNow.getDate();
       var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
          datepaid.value = datePaid; 
    prevbal.value = parseFloat(amtdue.value) + parseFloat(shipamt.value) - parseFloat(paidamt.value);
    amtdue.value = parseFloat(amtdue.value) + parseFloat(shipamt.value) - parseFloat(paidamt.value);
    checkno.value = parseInt(checkno.value) + "1";
       if(recur.value=="N")
          {prevbal.value= amtdue.value;} 
       if(prevbal.value=="0.00")
          {pd="P";} 
       if(amtdue.value=="0.00")
          {pd="P";}

  2. #2
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    document.getElementById(<id>) returns an element who's id attribute is <id> or null (on failure).
    All the form elements use name attributes not id attributes. You can either replace all the attribute name to id. or you can use document.forms[<N>].elements[<name>] (replace <N> with the index the form falls in, most likely 0, replace <name> with the name attribute you need to access).
    Code:
    var theForm = document.forms[0];
    theForm.elements["shipamt"].value

  3. #3
    Join Date
    Apr 2013
    Posts
    73
    thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles