Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto insert

Status
Not open for further replies.

ckdoublenecks

Programmer
Dec 28, 2010
9
US
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 .

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>
<?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'] . "'></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"; 
} 
?> 
<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) ? "[URL unfurl="true"]https://ssl."[/URL] : "[URL unfurl="true"]http://www.");[/URL]
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) ? "[URL unfurl="true"]https://ssl."[/URL] : "[URL unfurl="true"]http://www.");[/URL]
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>
 
Did you try looking at the error message(s) your browser should have reported to you? For me in Firefox, they immediately identify the problem:

missing } after function body (line 27)

That aside, why bother defining the function $_ as a shortcut to document.getElementById if you're not going to use it (i.e. lines 6-14)?

If you're still having problems after fixing the missing brace (which your browser should have told you about), then post the client-side code, not the unparsed server-side code.

Hope this helps,

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Dan - son - I'm just tring to learn this stuff and I'm really confused now. My menory is really bad and I had help with the original of this program a couple of years ago, which is and has been running for over a year. I'm trying my best to modify it to use it in another application. I can't for the life of me see the difference in the code of the two. Would it help if I posted the working version. Right now my code does the insertions but I get "Query failed". Below is my current 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 pd = document.getElementById("pd");
var datepaid = document.getElementById("datepaid");
var amtdue = document.getElementById("amtdue");
var paidamt = document.getElementById("paidamt");
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 & set up pd***
amtdue.value = parseFloat(amtdue.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
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 Amt</th>
<th>Amt Due</th>
<th>Date Paid</th>
<th>Code</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='amtdue' name='charges' value='" . $row['amtdue'] ."'></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'] . "'
onBlur='calculate_paid(this)'></td>
<td><input type='text' size=7 name='paidsum' value='" . $row['paidsum'] . "'
onBlur='calculate_paid(this)'></td>
</tr>";
}
echo "</table>
<input type='submit' name='update' value='Make Payment' />
</form>";
}
else{echo "No listing for invoice no. $invnum.<br />Please select another.<br />";}
}
if(!empty($_POST["update"]))
{
$sql = "UPDATE payments SET
pd = '" . mysql_real_escape_string($_POST['pd']) . "',
datepaid = '" . mysql_real_escape_string($_POST['datepaid']) . "',
paidamt = '" . mysql_real_escape_string($_POST['paidamt']) . "',
amtdue = '" . mysql_real_escape_string($_POST['amtdue']) . "',
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";
}
?>
<form method="post" action="#">
<br />
<input type="text" name="invnum"/> <p>
<input type="submit" name="submit" value="select invoice no."/>
</form>
<script type="text/javascript"><!--
var gaJsHost = (("https:" == document.location.protocol) ? " : "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) ? " : "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>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top