₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,108 members, 8,420,370 topics. Date: Thursday, 04 June 2026 at 05:54 PM

Toggle theme

Trying To Insert Fields Into Input - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingTrying To Insert Fields Into Input (902 Views)

1 Reply

Trying To Insert Fields Into Input by ckdoublene(op): 9:02pm On Dec 22, 2010
I want to insert fields into the input when I key in the amtpaid .  Currently I get no errors but the only field inserted is the datepaid Can someone look at the code, please?

<html><head>
<script>
function $_(IDS) { return document.getElementById(IDS); }
function calculate_paid() {
  var amtpaid = parseInt($_("amtpaid"wink.value);
  var rentdue = parseInt($_("rentdue"wink.value);
  var prevbal = parseInt($_("prevbal"wink.value);
  var secdep = parseInt($_("secdep"wink.value);
  var latechg = parseInt($_("latechg"wink.value);
  var damage = parseInt($_("damage"wink.value);
  var courtcost = parseInt($_("courtcost"wink.value);
  var nsf = parseInt($_("nsf"wink.value);
  var hudpay = parseInt($_("hudpay"wink.value);
  var late = ($_("late"wink.value);
  var paidsum = parseInt($_("paidsum"wink.value);
  var dateNow = new Date();
  var dayNow = dateNow.getDate();
  var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
  $_('datePaid').value = datePaid;
      if(dayNow > 5) { late = "L"; prevbal = prevbal + 10; }
paidsum = paidsum + amtpaid
  var tentpay = amtpaid - hudpay;
  var totOwed = rentdue + prevbal - hudpay;
  var left = totOwed - amtpaid;
    if (amtpaid <= totOwed) { prevbal = left; }
left = amtpaid - totOwed;
  if (left <= secdep) { secdep = secdep - left; }
left = left - secdep;
  if (left <= damage) { damage = damage - left; }
left = left - damage;
  if (left <= latechg) { latechg = latechg - left; }
left = left - latechg;
  if (left <= courtcost) { courtcost = courtcost - left; }
left = left - courtcost;
  if (left <= nsf) { nsf = nsf - left; }
prevbal = left - nsf;
}
</script>
</head><body>
<?php
mysql_connect(localhost,root,""wink;
mysql_select_db(test) or die( "Unable to select database"wink;
if(!empty($_POST["submit"]))
{
$apt = $_POST['apt'];
$query="SELECT * FROM testdata Where apt='$apt'";
$result=mysql_query($query);
if(mysql_num_rows($result))
{
echo "<form action='#' method='post'><b>Rent Payment :


<table cellspacing=0 cellpadding=0 border=1>
<tr>
  <th>Name</th>
  <th>Apt</th>
  <th>Paid</th>
  <th>Due</th>
  <th>Prev Bal</th>
   <th>Sec Dep</th>
   <th>Late Chg</th>
   <th>Dmg</th>
   <th>Court Cost</th>
   <th>NSF</th>
  <th>Tent Pay</th>
  <th>Hud Pay</th>
    <th>Date Paid</th>
  <th>Late</th>
  <th>Comments</th>
<th>Paidsum</th>
</tr>";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>
<td><input type='text' size=25 name='name' value='" . $row['name'] . "'></td>
<td><input type='text' size=2 name='apt' value='" . $row['apt'] . "' ></td>
<td><input type='text' size=4 id='amtpaid' name='amtpaid' value='" . $row['amtpaid'] ."' onBlur='calculate_paid(this)'></td>
<td><input type='text' size=4 id='rentdue' name='rentdue' value='" . $row['rentdue'] . "'></td>
<td><input type='text' size=4 id='prevbal' name='prevbal' value='" . $row['prevbal'] ."'></td>
<td><input type='text' size=4 id='secdep' name='secdep' value='" . $row['secdep'] ."'></td>
<td><input type='text' size=4 id='latechg' name='latechg' value='" . $row['latechg'] ."'></td>
<td><input type='text' size=4 id='damage' name='damage' value='" . $row['damage'] ."'></td>
<td><input type='text' size=4 id='courtcost' name='courtcost' value='" . $row['courtcost'] ."'></td>
<td><input type='text' size=4 id='nsf' name='nsf' value='" . $row['nsf'] ."'></td>
<td><input type='text' size=4 id='tentpay' name='tentpay' value='" . $row['tentpay'] . "'></td>
<td><input type='text' size=4 id='hudpay' name='hudpay' value='" . $row['hudpay'] ."'></td>
<td><input type='text' size=10 id='datepaid' name='datepaid' value='" . $row['datepaid'] . "'></td>
<td><input type='text' size=1 id='late' name='late' value='" . $row['late'] . "'></td>
<td><input type='text' size=25 name='comments' value='" . $row['comments'] . "'></td>
<td><input type='text' size=4 id='paidsum' name='paidsum' value='" . $row['paidsum'] . "'></td>
</tr>";
}
echo "</table>
<input type='submit' name='update' value='Make Payment' />
</form>";
}
else{echo "No listing for apartment $apt.
Please select another.
";}
}
if(!empty($_POST["update"]))
{
$sql = "UPDATE testdata SET
name = '" . mysql_real_escape_string($_POST['name']) . "',
amtpaid = '" . mysql_real_escape_string($_POST['amtpaid']) . "',
rentdue = '" . mysql_real_escape_string($_POST['rentdue']) . "',
prevbal = '" . mysql_real_escape_string($_POST['prevbal']) . "',
secdep = '" . mysql_real_escape_string($_POST['secdep']) . "',
latechg = '" . mysql_real_escape_string($_POST['latechg']) . "',
nsf = '" . mysql_real_escape_string($_POST['nsf']) . "',
damage = '" . mysql_real_escape_string($_POST['damage']) . "',
courtcost = '" . mysql_real_escape_string($_POST['costcost']) . "',
tentpay = '" . mysql_real_escape_string($_POST['tentpay']) . "',
hudpay = '" . mysql_real_escape_string($_POST['hudpay']) . "',
datepaid = '" . mysql_real_escape_string($_POST['datepaid']) . "',
late = '" . mysql_real_escape_string($_POST['late']) . "',
comments = '" . mysql_real_escape_string($_POST['comments']) . "',
paidsum = '" . mysql_real_escape_string($_POST['paidsum']) . "'
WHERE apt='".$_POST["apt"]."'";
mysql_query($sql) or die("Update query failed."wink;
echo "Record for apartment ".$_POST["apt"]." has been updated";
}
?>
<form method="post" action="#">


<input type="text" name="apt"/> <p>
<input type="submit" name="submit" value="select apartment"/>
</form>
</body></html>
Re: Trying To Insert Fields Into Input by Nobody: 6:55am On Dec 23, 2010
Check your DataBase Mapping to See if all Table name correspond with the Arrays there,i think you should:
1.Get a Good IDE Debug and view the Variables to see what the Database Returns to you, you can use the Zend Debugger
2.using vardump print the returned value from the Database.
1 Reply

Help! Cannot Get Json Array Into Input Field - JqueryHow To Insert Pictures Or Images In Textedit (webdesign)Please Help On How To Insert Smiley In An Output Text In Java Script234

How Well Do You Understand And Write Your Local Language?Class/meta ClassJava Programmer Help Me Out With This Problem