SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: auto insert

  1. #1
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    auto insert

    I took a working program and modified it to use different values and can't seem to make it work now. I want have the datepaid, pd & paidsum insert when I key in the amtpaid .

    HTML Code:
    <html><head>
    <!--when the paidamt is keyed in, the current date, pd & paidsum are autoinserted-->
    <script>
    function $_(IDS) { return document.getElementById(IDS); }
    function calculate_paid() {
       var invnum = document.getElementById("invnum");
       var ordernum = document.getElementById("ordernum");
       var bname = document.getElementById("bname");
       var charges = document.getElementById("charges");
       var paidamt = document.getElementById("paidamt");
       var tax = document.getElementById("tax");
       var datepaid = document.getElementById("datepaid");
       var pd = document.getElementById("pd");
       var paidsum = document.getElementById("paidsum");
    <!--********************set up date**********************-->
      var dateNow = new Date();
      var dayNow = dateNow.getDate();
      var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
    datepaid.value = datePaid;
    <!--end date setup-->
    <!--accumulate charges into paidsum, calculate tax, set up pd & calculate dayslate (?)--> 
    charges.value = parseFloat(charges.value);
    paidsum.value = parseFloat(paidsum.value) + parseFloat(paidamt.value);
    tax.value= parseFloat(charges.value) * .06;
    pd.value = "P";
    <!--********************* end of calcs ******************-->
    </script>
    <script type="text/javascript">
    window.google_analytics_uacct = "UA-256751-2";
    </script>
    <script type="text/javascript">
    window.google_analytics_uacct = "UA-256751-2";
    </script>
    </head><body><form method="post" action="#">
    <br />
    <input type="text" name="invnum"/> <p>
    <input type="submit" name="submit" value="select inv#"/>
    </form>
    <script type="text/javascript"><!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    //-->
    </script>
    <script type="text/javascript"><!--
    try {
    var pageTracker = _gat._getTracker("UA-256751-2");
    pageTracker._trackPageview();
    } catch(err) {}
    //-->
    </script>
    <script type="text/javascript"><!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    //-->
    </script>
    <script type="text/javascript"><!--
    try {
    var pageTracker = _gat._getTracker("UA-256751-2");
    pageTracker._trackPageview();
    } catch(err) {}
    //-->
    </script>
    </body></html>

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    To encourage people to take your post more seriously, you need to strip out the irrelevant garbage and post only the necessary code to understand the problem. If PHP is not relevant to the issue, just post the HTML the javascript will be working with.

    In addition, you need to be clearer when explaining the issue. For example, "amtpaid" doesn't exist anywhere in the code you posted.

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot for the help. please look at it now. I can't believe I can't convert my working version to this ?

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Still a lot of garbage there (all the google analytics stuff) making it harder to read. Plus, it's impossible to see how this all works, since it looks like some of the HTML is missing. The only visible HTML is this:

    HTML Code:
    <form method="post" action="#">
    <br />
    <input type="text" name="invnum"/> <p>
    <input type="submit" name="submit" value="select inv#"/>
    </form>
    Plus, it's impossible to see how calculate_paid() is supposed to be called, or where all these values are supposed to go.

    Pretty obvious really, but you need to think carefully about what it's like for someone unfamiliar with your code to try to help you. You can't supply half the information necessary and expect them to understand what's going on.

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You guys do a great job and I know its to hard to see what I'm trying to do. below I've disclosed the javascript and below that the input portion. I really hope you can help
    HTML Code:
    .<script>
    function $_(IDS) { return document.getElementById(IDS); }
    function calculate_paid() {
       var invnum = document.getElementById("invnum");
       var ordernum = document.getElementById("ordernum");
       var bname = document.getElementById("bname");
       var charges = document.getElementById("charges");
       var paidamt = document.getElementById("paidamt");
       var tax = document.getElementById("tax");
       var datepaid = document.getElementById("datepaid");
       var pd = document.getElementById("pd");
       var paidsum = document.getElementById("paidsum");
    <!--********************set up date**********************-->
      var dateNow = new Date();
      var dayNow = dateNow.getDate();
      var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
    datepaid.value = datePaid;
    <!--end date setup-->
    <!--accumulate charges into paidsum, calculate tax, set up pd & calculate dayslate (?)--> 
    charges.value = parseFloat(charges.value);
    paidsum.value = parseFloat(paidsum.value) + parseFloat(paidamt.value);
    tax.value= parseFloat(charges.value) * .06;
    pd.value = "P";
    <!--********************* end of calcs ******************-->
    </script>
    PHP Code:
    <td><input type='text' size=5 name='invnum' value='" . $row['invnum'] . "'></td>
    <
    td><input type='text' size=5 name='ordernum' value='" . $row['ordernum'] . "'></td>
    <
    td><input type='text' size=25 name='bname' value='" . $row['bname'] . "' ></td>
    <
    td><input type='text' size=25 name='descr' value='" . $row['descr'] . "' ></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='charges' name='charges' value='" . $row['charges'] ."'
    onBlur='calculate_paid(this)'></td>
    <
    td><input type='text' size=10 id='datepaid' name='datepaid' value='" . $row['datepaid'] . "'></td>
    <
    td><input type='text' size=1 id='pd' name='pd' value='" . $row['pd'] . "'></td>
    <
    td><input type='text' size=7 name='paidsum' value='" . $row['paidsum'] . "' ></td

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Much better. Obviously this is what you should have posted from the outset.

    So are you saying that when you click away from paidamt, the values for charges and paidsum do not appear?

    The likelihood is because you've sprinkled the JavaScript with these HTML comments (not sure why I didn't notice that before!):

    HTML Code:
    <!--********************set up date**********************-->
    JavaScript comments are like this:

    Code javascript:
    // an inline comment
     
    /*  A 
    block
    comment
    */

    HTML comments will therefore be invalid JavaScript. This would probably have been picked up had you used Firebug or some other debugging software.

  7. #7
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So are you saying that when you click away from paidamt, the values for charges and paidsum do not appear?
    that is what is happening -
    The likelihood is because you've sprinkled the JavaScript with these HTML comments
    I recommented but still the same results

  8. #8
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The calculate_paid function doesn't have a closing brace ( } ).

    Like I said, simple things like these would be caught by Firebug.

  9. #9
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try this example to help you out based on some of the code you provided:

    Code HTML4Strict:
    <html>
    	<body>
    		<form name="testForm">
    			<label>PAIDAMT</label>
    				<input type='text' name='paidamt' value='' />
    				<br />
    			<label>DATEPAID</label>
    				<input type='text' name='datepaid' value='' />
    				<br />
    			<label>PD</label>
    				<input type='text' name='pd' value='' />
    				<br />
    			<label>PAIDSUM</label>
    				<input type='text' name='paidsum' value='' />
    				<br />
    		</form>
    		<script>
    			document.testForm.paidamt.onblur = function() {
    				document.testForm.datepaid.value = currDate();
    				document.testForm.pd.value = 'P';
    				document.testForm.paidsum.value = this.value * 0.6;
    			}
     
    			function currDate() {
    				var dateNow = new Date(),
      					dayNow = dateNow.getDate();		
    				return (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
    			}
    		</script>
    	</body>
    </html>

  10. #10
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    with this code everything jumps into place but i get:
    update query failed
    HTML Code:
    <html><head>
    <!--when the paidamt is keyed in, the current date, pd & paidsum are autoinserted-->
    <script>
    function $_(IDS) { return document.getElementById(IDS); }
    function calculate_paid() {
       var invnum = document.getElementById("invnum");
       var ordernum = document.getElementById("ordernum");
       var bname = document.getElementById("bname");
       var charges = document.getElementById("charges");
       var paidamt = document.getElementById("paidamt");
       var tax = document.getElementById("tax");
       var datepaid = document.getElementById("datepaid");
       var pd = document.getElementById("pd");
       var paidsum = document.getElementById("paidsum");
    // ********************set up date**********************
      var dateNow = new Date();
      var dayNow = dateNow.getDate();
      var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
    datepaid.value = datePaid;
    // end date setup
    // accumulate charges into paidsum, calculate tax, set up pd & calculate dayslate (?) 
    charges.value = parseFloat(charges.value);
    paidsum.value = parseFloat(paidsum.value) + parseFloat(paidamt.value);
    pd.value = "P";
    // ********************* end of calcs ******************
    }
    </script>
    <script type="text/javascript">
    window.google_analytics_uacct = "UA-256751-2";
    </script>
    <script type="text/javascript">
    window.google_analytics_uacct = "UA-256751-2";
    </script>
    </head><body>
    PHP Code:
    <?php
    mysql_connect
    (localhost,root,"");
    mysql_select_db(oodb) or die( "Unable to select database");
    if(!empty(
    $_POST["submit"]))
    {
    $invnum $_POST['invnum'];
    $query="SELECT * FROM oocust Where invnum='$invnum'";
    $result=mysql_query($query);
    if(
    mysql_num_rows($result))
    {
    echo 
    "<form action='#' method='post'><b>Invoice Payment :<br /><br />
    <table cellspacing=0 cellpadding=0 border=1>
        <tr>
      <th>Inv#</th>
      <th>ord#</th>
      <th>Name</th>
      <th>Description</th>
      <th>Paid</th>
      <th>Charges</th>
      <th>Date Paid</th>
      <th>Pd</th>
      <th>Total</th>
          </tr>"
    ;
    while(
    $row mysql_fetch_assoc($result))
    {
     echo 
    "<tr>
    <td><input type='text' size=5 name='invnum' value='" 
    $row['invnum'] . "'></td>
    <td><input type='text' size=5 name='ordernum' value='" 
    $row['ordernum'] . "'></td>
    <td><input type='text' size=25 name='bname' value='" 
    $row['bname'] . "' ></td>
    <td><input type='text' size=25 name='descr' value='" 
    $row['descr'] . "' ></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='charges' name='charges' value='" 
    $row['charges'] ."'
    onBlur='calculate_paid(this)'></td>
    <td><input type='text' size=10 id='datepaid' name='datepaid' value='" 
    $row['datepaid'] . "'
    onBlur='calculate_paid(this)'></td>
    <td><input type='text' size=1 id='pd' name='pd' value='" 
    $row['pd'] . "'></td>
    <td><input type='text' size=7 name='paidsum' value='" 
    $row['paidsum'] . "' ></td>   
    </tr>"

    }
    echo 
    "</table>
    <input type='submit' name='update' value='Make Payment' />
    </form>"
    ;
    }
    else{echo 
    "No listing for invoice# $invnum.<br />Please select another.<br />";}
    }
    if(!empty(
    $_POST["update"]))
    {
    $sql "UPDATE payments SET
    invnum = '" 
    mysql_real_escape_string($_POST['invnum']) . "',
    ordernum = '" 
    mysql_real_escape_string($_POST['ordernum']) . "',
    bname = '" 
    mysql_real_escape_string($_POST['bname']) . "',
    descr = '" 
    mysql_real_escape_string($_POST['descr']) . "',
    paidamt = '" 
    mysql_real_escape_string($_POST['paidamt']) . "',
    charges = '" 
    mysql_real_escape_string($_POST['charges']) . "',
    datepaid = '" 
    mysql_real_escape_string($_POST['datepaid']) . "',
    pd = '" 
    mysql_real_escape_string($_POST['pd']) . "',
    paidsum = '" 
    mysql_real_escape_string($_POST['paidsum']) . "'
    WHERE invnum='"
    .$_POST["invnum"]."'";
    mysql_query($sql) or die("Update query failed.");
    echo 
    "Record for invoice ".$_POST["invnum"]." has been updated";
    }
    ?>
    HTML Code:
    <form method="post" action="#">
    <br />
    <input type="text" name="invnum"/> <p>
    <input type="submit" name="submit" value="select inv#"/>
    </form>
    <script type="text/javascript"><!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    //-->
    </script>
    <script type="text/javascript"><!--
    try {
    var pageTracker = _gat._getTracker("UA-256751-2");
    pageTracker._trackPageview();
    } catch(err) {}
    //-->
    </script>
    <script type="text/javascript"><!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    //-->
    </script>
    <script type="text/javascript"><!--
    try {
    var pageTracker = _gat._getTracker("UA-256751-2");
    pageTracker._trackPageview();
    } catch(err) {}
    //-->
    </script>
    </body></html>


Bookmarks

Posting Permissions

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