Jump to content

spires

Members
  • Posts

    492
  • Joined

  • Last visited

Everything posted by spires

  1. Hi First, I really appreciate your help on this, I never would have got this far with you. Anyway. var_dump($user); is outputting: array(10) { [0]=> string(1) "1" ["photo_id"]=> string(1) "1" [1]=> string(6) "spires" ["photo_user"]=> string(6) "spires" [2]=> string(7) "ss16" ["photo_pass"]=> string(7) "ss16" [3]=> string(4) "Jeff" ["photo_Fname"]=> string(4) "Jeff" [4]=> string(6) "Spires" ["photo_Lname"]=> string(6) "Spires" } The 2nd error: I have removed the = but I am still getting the same error. Any more ideas would be great.
  2. Hi Thanks I didn't know I could do that to see the errors. Anyway, I fix one of the bugs, but I am left with a new one. Error 1: Notice: Trying to get property of non-object in /var/www/html/businessmobiles.com/OOP/photo_gallery/public/user3.php on line 9 Error 2: Warning: Invalid argument supplied for foreach() in /var/www/html/businessmobiles.com/OOP/photo_gallery/public/user3.php on line 14 $user = User::find_by_id(1); echo $user->id; echo "<hr />"; $users = User::find_all(); foreach($users as $user) { echo "User: ". $user->username ."<br />"; echo "Name: ". $user->first_name ."<br /><br />"; } Error 1 points to : echo $user->id; Error 2 points to : foreach($users as $user) { Any help on this would be great as i'm completely stuck. Thanks
  3. Hi guys. I'm just learning OOP for the first time, I'm trying to create a user class (see below). But I can't seem to get it to work, I know there's an error, but my server is set up so it doesn't show any error. I would really appreciate any help Class <?PHP // Users Class require_once('database.php'); class User { public $id; public $username; public $password; public $first_name; public $last_name; ////// public static function find_all() { return = self::find_by_sql("SELECT * FROM photo_gallery_users"); } ////// public static function find_by_id($id="") { global $database; $result_array = self::find_by_sql("SELECT * FROM photo_gallery_users WHERE photo_id='{$id}' LIMIT 1"); return !empty($result_array) ? array_shift($result_array) : false; } ////// public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); $object_array = array(); while ($row = $database->fetch_array($result_set)) { $object_array[] = self::instantiate($row); } return $object_array; } ////// private static function instantiate($record) { $object = new self; foreach($record as $attribute=>$value) { if($object->has_attribute($attribute)) { $object->$attribute = $value; } } return $object; } ////// private function has_attribute($attribute) { $object_vars = get_object_vars($this); return array_key_exists($attribute, $object_vars); } } ?> HTML <?PHP require_once("../includes/database.php"); require_once("../includes/user.php"); // record or row $user = User::find_by_id(1); echo $user->id; echo "<hr />"; $users = User::find_all(); foreach ($users as $user) { echo "ID: " . $user->id . "<br>"; echo "user: " . $user->username . "<br>"; } Thanks
  4. ok wildTeen88, I shall give that a go. Thanks
  5. Hi I have a function inside on one include file. I also have another function inside of another include file. What I need to be able to do is call one of the functions inside the other function. Can this be done? Here's my code for the main function which is trying to call other function into it: Calling functions: landline_anynetwork_mins() - landline_anynetwork_price() <?php function myFunction(){ include("Library/deal_variables.php"); echo' <table width="165" height="163" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center" valign="top" background="GFX/Page_Business_mobiles/Column_Call_Action/Latest_offers.jpg"> <table width="145" height="158" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="31" colspan="3" align="left"><a href="latest_offers_open.php" class="link">Our Latest Offers</a> </td> </tr> <tr> <td width="43" height="36" align="left" valign="top"></td> <td width="15" align="center" valign="top"><img src="GFX/Wrapper_Business_Mobiles/Call_arrow.jpg" alt="business mobiles for business people" width="5" height="11" /></td> <td width="87" align="left" valign="top"><a href="deal_landline_anynetwork.php" class="prodNavi">'.landline_anynetwork_mins().' mins for £'.landline_anynetwork_price().'</a></td> </tr> <tr> </table> </td> </tr> </table>'; } ?> As you can see here, it outputs the results above the table, not in the position that I want them. http://www.businessmobiles.com/test2.php Any help would be great. Thanks
  6. Hi I am still running a server with PHP4, but it has now come to a point where I need to upgrade to PHP5. However, It would be great if I could get some advice from you guys first. - Will my website that was built in php4 still work? - is there a list of functions that no longer work? - What are the chances of my old site breaking? Thanks for your help.
  7. Hi guys. I'm trying to do a simple function, but for some reason the value won't return? I can echo the value out, but not return the value. What am I doing wrong? <?PHP include("../dbconnect.php"); $usName = $_SESSION["usName"]; function sevenDays($day, $usName){ $notes_sel_sql = "SELECT * FROM csv_notes WHERE notes_user='$usName' && notes_status2='Awaiting proofs' && notes_date2 >= DATE_SUB(CURDATE(), INTERVAL $day DAY)"; $notes_sel_result = mysql_query($notes_sel_sql) or die ("query 2 failed".mysql_error()); $notes_sel_count = mysql_num_rows($notes_sel_result); $arrGP = array(); for ($i=0;$i<$notes_sel_count;$i++){ $notes_sel_row = mysql_fetch_array($notes_sel_result); $totalGP = $notes_sel_row['notes_Totalgp']; $arrGP[] = $totalGP; } $totalSum = array_sum($arrGP); return $totalSum; } $days = '7'; sevenDays($days, $usName); ?> Like I said, if I do 'echo $totalSum; instead of return $totalSum;' then it works fine. Also, why should I use return over echo? Thanks
  8. Hi guys. I'm trying to select all enteries from my database within the last 7 days. $todaysDate = date("d/m/Y"); SELECT * FROM csv_notes WHERE notes_date2 >= DATE_SUB($todaysDate, INTERVAL 7 DAY) The data in the data base are: 19/06/2009 20/06/2009 21/06/2009 22/06/2009 23/06/2009 However, it's not selecting anything? Can someone please let me know what i'm doing wrong. Thanks
  9. Solved. Thanks guys $subEnd = date("m/d/Y H:i:s"); $timeLeft = (strtotime($subEnd) - strtotime($notes_date)); $mins = floor($timeLeft / 60); $secs = $timeLeft - ($mins * 60); $hours = floor($mins / 60); $mins = $mins - ($hours * 60); $days = floor($hours / 24); $hours = $hours - ($days * 24); $diffDate = "{$days}d, {$hours}h, {$mins}min";
  10. Hi, Your code works perfect. However, at the moment it counts down, how do I get it to count up? I want to put in a start date, If I do that in your code, I get -3 days, rather than 3 days. Please see: http://www.businessmobiles.com/comcalc/test4.php Your code: $subEnd = date("6/22/2009 11:08:30"); $timeLeft = (strtotime($subEnd) - time()); $mins = floor($timeLeft / 60); $secs = $timeLeft - ($mins * 60); $hours = floor($mins / 60); $mins = $mins - ($hours * 60); $days = floor($hours / 24); $hours = $hours - ($days * 24); echo "You have {$days} days, {$hours} hours, {$mins} minutes and {$secs} seconds remaining of your subscription"; Thanks
  11. Thanks, that look like it will do the trick. One thing though, what is $subEnd. Is it the date and time? e.g 24/06/2009 09:41:26 Thanks
  12. Hi guys. I have a date and time stored in my database: 24/06/2009 09:41:26 What I need to be able to do is see how much time has passed. Example: Todays date & time - Stored date & time = 01d 05h 58min has passed i'm really stuck on this, does anyone of any date function that can do this? Thanks for your help.
  13. Solved var city = []; function notes(){ var nList = document.getElementById("notesDropdown").value; city[city.length] = nList; var msg = ""; for (x = 0; x < city.length; x++) { document.getElementById("test").value = x; msg += city[x] + ", "; } document.getElementById("finalNotes").value=msg; }
  14. It does, but I need each time an option is selected, it stores it into the array. So this is what i'm doing now: city[city.length] = nList; If 1 value is in the array, this will become city[0], However, the count is 1, which means on the next pass the array will become city[1], and the count will be 2. This seems to be working ok, the array is storing the values, but I can't seem to display every value in the array now. I thought this would be easy, no such luck <script> var city = []; var msg = ""; function notes(){ var nList = document.getElementById("notesDropdown").value; city[city.length] = nList; alert(city.length); for (x = 0; x < city.length; x++) { msg = city[x] + ", "; } document.getElementById("finalNotes").value=msg; } </script>
  15. Hi Thanks for your help. I'm sure your on the right track, but it did not work. The array keeps getting reset every time I select a new option. Up to date code: <script> var city = []; var msg = ""; function notes(){ var nList = document.getElementById("notesDropdown").value; var cLength = city.length + 1; for (x = 0; x < cLength; x++) { city[x] = nList; msg = city[x] + ", "; } document.getElementById("finalNotes").value=msg; } </script> Any more advice would be great
  16. Hi I'm getting closer: Please see: http://www.businessmobiles.com/comcalc/test4.php All I need to do now is work out how to keep adding to the array. At the moment each time I select from the drop down list, it overwrites the old array. Any help please? New code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> <script> function notes(){ var nList = document.getElementById("notesDropdown").value; var city = []; city[0] = nList; var msg = ""; for (x = 0; x < city.length; x++) { msg = msg + city[x] + ", ";; } document.getElementById("finalNotes").value=msg; } </script> </head> <body> <form name="finalNotesList" action="test4.php" method="post"> <select name="notesDropdown" size="0" onchange="notes();" id="notesDropdown" style="width:220px; font-size:10px;" > <option value=""> </option> <option value="Number port on Line 1">Number port on Line 1</option> <option value="Add International Roaming to Line">Add International Roaming to Line</option> <option value="Add International Call">Add International Call</option> <option value="Upgrade on Line">Upgrade on Line</option> </select> <br><br> <textarea name="finalNotes" rows="3" cols="75" id="finalNotes"></textarea> <br><br> <input type="submit" name="finalNotesList" value="Submit" /> </form> </body> </html>
  17. Hi Guys I need help trying to create and display an array. I have a dropdown list, when an option is selected, this needs to be stored in an array. Then each array needs to be displayed in a text area. You can select multiple options, giving you multiple values in the text area. Please see: http://www.businessmobiles.com/comcalc/test4.php Any help would be great. Here is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> <script language="javascript"> function notes() { var nList = document.getElementById("notesDropdown").value; var notesArray = new Array(); notesArray[] = nList; for (x = 0; x < numListedInArray; x++){ document.getElementById("finalNotes").value=notesArray[x]+','; } } </script> </head> <body> <form name="finalNotesList" action="test4.php" method="post"> <select name="notesDropdown" size="0" onchange="notes()" id="notesDropdown" style="width:220px; font-size:10px;" > <option value=""> </option> <option value="Number port on Line 1">Number port on Line 1</option> <option value="Add International Roaming to Line">Add International Roaming to Line</option> <option value="Add International Call">Add International Call</option> <option value="Upgrade on Line">Upgrade on Line</option> </select> <br><br> <textarea name="finalNotes" rows="3" cols="75" id="finalNotes" value=""></textarea> <br><br> <input type="submit" name="finalNotesList" value="Submit" /> </form> </body> </html>
  18. Hi guys I want to turn a 1000 into 1,000.00 How is this done using php? Thanks for your help
  19. Hi Guys. I have a form which is working fine: http://www.businessmobiles.com/comcalc/test3.php However, if change anything in row 1, it automatically update row 2 and 3. I think it has something to do with onkeyup event, but I not sure what. If you want to see this problem, goto: http://www.businessmobiles.com/comcalc/test3.php and change the '5' in the first field. You will then see that row 2 and 3's fields will get populated. How do I stop this? My code - Javascript function calculate2(num) { var rCount=document.getElementById("rowCount").value; for(i = 0; i < rCount; i++){ if (num==1){ document.getElementById("monthly_discount_xQ"+i).value=nan(document.getElementById("monthly_discount"+i).value)*nan(document.getElementById("STqty"+i).value); document.getElementById("rental_after_discount"+i).value=nan(document.getElementById("STlr"+i).value)-nan(document.getElementById("monthly_discount"+i).value); }else if (num==2){ document.getElementById("monthly_discount"+i).value=nan(document.getElementById("monthly_discount_xQ"+i).value)/nan(document.getElementById("STqty"+i).value); document.getElementById("rental_after_discount"+i).value=nan(document.getElementById("STlr"+i).value)-nan(document.getElementById("monthly_discount"+i).value); }else if (num==3){ document.getElementById("monthly_discount"+i).value=nan(document.getElementById("STlr"+i).value)-nan(document.getElementById("rental_after_discount"+i).value); document.getElementById("monthly_discount_xQ"+i).value=nan(document.getElementById("monthly_discount"+i).value)*nan(document.getElementById("STqty"+i).value); } } } Cleaner Code, first input field: <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount" type="text" size="4" class="verdana_10" height="10" value="'.$stored_monthly_discount1.'" onchange="calculate2(1);" onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(1);" onblur="calculate2(1);" id="monthly_discount'.$i1.'" /> </td> Full Code - My HTML/PHP <?PHP $usName = 'spires'; $client = 'tim'; $job_id = '1'; $stored_sql1 = "SELECT * FROM csv_stored WHERE stored_user='$usName' && stored_client='$client' && stored_job_id='$job_id' ORDER by stored_id ASC"; $stored_result1 = mysql_query($stored_sql1) or die ("query 2 failed".mysql_error()); $stored_count1 = mysql_num_rows($stored_result1); for ($i1 = 0; $i1<$stored_count1; $i1++){ echo ' <form name="cashFlow'.$i1.'" action="test.php" method="post"> <input name="job_id" type="hidden" value="'.$job_id.'"/> <input name="client" type="hidden" value="'.$client.'"/> <tr bgcolor="#FFFFFF" onMouseOver="this.bgColor=\'#EEEEEE\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'; $stored_row1 = mysql_fetch_assoc($stored_result1); $stored_id1 = $stored_row1['stored_id']; $stored_product1 = $stored_row1['stored_product']; $stored_product_price1 = $stored_row1['stored_product_price']; $stored_item1 = $stored_row1['stored_item']; $stored_item_line_rental1 = $stored_row1['stored_item_line_rental']; $stored_unit_price1 = $stored_row1['stored_unit_price']; $stored_subtotal1 = $stored_row1['stored_subtotal']; $stored_pHandset1 = $stored_row1['stored_pHandset']; $stored_commissions1 = $stored_row1['stored_commissions']; $stored_qty1 = $stored_row1['stored_qty']; $stored_num1 = $stored_row1['stored_num']; $stored_totalMR1 = $stored_row1['totalMR']; $stored_monthly_discount1 = $stored_row1['monthly_discount']; $stored_monthly_discount_xQ1 = $stored_row1['monthly_discount_xQ']; $stored_duration1 = $stored_row1['duration']; $stored_discount_total1 = $stored_row1['discount_total']; $stored_discount_total_xQ1 = $stored_row1['discount_total_xQ']; $stored_rental_after_discount1 = $stored_row1['rental_after_discount']; $stored_rental_after_discount_xQ1 = $stored_row1['rental_after_discount_xQ']; if ($stored_product1=='add'){ $stored_product1 = 'Add to line '.$stored_num1; } $item_str1 = str_replace(' Month', 'mth', $stored_item1); $j1 = $i1+1; $TotalMRxQ = $stored_item_line_rental1 * $stored_qty1; $discount_total_xQ = $stored_monthly_discount_xQ1 * $stored_duration1; $stored_rental_after_discount_xQ1 = $TotalMRxQ - $discount_total_xQ; echo ' <td height="17" class="verdana_9" align="left"><input name="storedID2" type="hidden" value="'.$stored_id1.'" /> <input name="rowNum" type="hidden" value="'.$i1.'" /> <input name="rowCount" type="hidden" value="'.$stored_count1.'" id="rowCount" />'.$j1.'</td> <td height="17" class="verdana_9" align="left"><input name="STqty" type="hidden" value="'.$stored_qty1.'" id="STqty'.$i1.'" />x'.$stored_qty1.'</td> <td height="17" class="verdana_9" align="left">'.$stored_product1.'</td> <td height="17" class="verdana_9" align="left">'.$item_str1.'</td> <td height="17" class="verdana_9" align="left"><input name="STlr" type="hidden" value="'.$stored_item_line_rental1.'" id="STlr'.$i1.'" />£'.$stored_item_line_rental1.'</td> <td height="17" class="verdana_9" align="left"><input name="STmr" type="hidden" value="'.$TotalMRxQ.'" id="STmr'.$i1.'" />£'.$TotalMRxQ.'</td> <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount" type="text" size="4" class="verdana_10" height="10" value="'.$stored_monthly_discount1.'" onchange="calculate2(1);" onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(1);" onblur="calculate2(1);" id="monthly_discount'.$i1.'" /> </td> <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount_xQ" type="text" size="4" class="verdana_10" height="10" value="'.$stored_monthly_discount_xQ1.'" onchange="calculate2(2);" onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(2);" onblur="calculate2(2);" id="monthly_discount_xQ'.$i1.'"/> </td> <td height="17" class="verdana_9" align="left"> <input name="duration" type="text" size="4" class="verdana_10" height="10" value="'.$stored_duration1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';" id="duration'.$i1.'" /> </td> <td height="17" class="verdana_9" align="left">£'.$stored_discount_total1.'</td> <td height="17" class="verdana_9" align="left">£'.$discount_total_xQ.'</td> <td height="17" class="verdana_9" align="left"> £<input name="rental_after_discount" type="text" size="4" class="verdana_10" height="10" value="'.$stored_rental_after_discount1.'" onchange="calculate2(3);" onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(3);" onblur="calculate2(3);" id="rental_after_discount'.$i1.'" /> </td> <td height="17" class="verdana_9" align="left"> £<input name="rental_after_discount_xQ" type="text" size="5" class="verdana_10" height="10" value="'.$stored_rental_after_discount_xQ1.'" onchange="calculate2(4);" onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2(4);" onblur="calculate2(4);" id="rental_after_discount_xQ'.$i1.'" /> </td> <td height="17" align="center"> <input type="submit" name="cashFlow'.$i1.'" size="10" value="update" /></td>'; echo '</tr> </form>'; } ?>
  20. Hi Guys I'm trying to build a form the does on the fly calculations. Please see: http://www.businessmobiles.com/comcalc/test.php The form need to fill out the blank fields when a user types in any of the fields, using onKeyUp event. So far I can only get the last field to work. So far no one else can seem to help. So any advice or help on how to do this would be great. I know it's the Javascript, but not to sure what. My code <?PHP include("../dbconnect.php"); include("../Library/head.php"); include("include.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Comcalc</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script language="javascript"> function fixCashFlow(i, t, q) { if (t=="mdisq") { // We need to set v=i.monthly_discount.value; i.monthly_discount_xQ.value=Math.floor((v*q*100))/100; } else { v=i.monthly_discount_xQ.value; i.monthly_discount.value=Math.floor(((v/q)*100))/100; } } function fixDiscount(frm, mlr, q, s) { mlr=parseFloat(mlr); if (s==false) { frm.monthly_discount.value=mlr-frm.rental_after_discount.value; fixCashFlow(frm, 'mdisq', q); } else { frm.rental_after_discount.value=Math.floor((frm.rental_after_discount_xQ.value/q)*100)/100; fixDiscount(frm, mlr, q, false); } } </script> </head> <body> <table width="930" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="20" colspan="14" align="left" valign="middle" bgcolor="#000000"><span class="title"><strong>Cash flow:</strong></span></td> </tr> <tr> <td width="32" height="20" align="left" valign="middle"><span class="verdana_10">Line</span></td> <td width="29" height="20" align="left" valign="middle"><span class="verdana_10">Qty</span></td> <td width="157" height="20" align="left" valign="middle"><span class="verdana_10">Products / Handsets</span></td> <td width="157" height="20" align="left" valign="middle"><span class="verdana_10">Tariff Name</span></td> <td width="54" height="20" align="left" valign="middle"><span class="verdana_10">Monthly line rental</span></td> <td width="40" height="20" align="left" valign="middle"><span class="verdana_10">Total MR <br /> x Q</span></td> <td width="54" height="20" align="left" valign="middle"><span class="verdana_10">Monthly discount</span></td> <td width="54" height="20" align="left" valign="middle"><span class="verdana_10">Monthly discount <br /> X Q</span></td> <td width="58" height="20" align="left" valign="middle"><span class="verdana_10">Duration (months)</span></td> <td width="70" height="20" align="left" valign="middle"><span class="verdana_10">Discounted Total</span></td> <td width="66" height="20" align="left" valign="middle"><span class="verdana_10">Discounted<br /> Total X Q</span></td> <td width="57" height="20" align="left" valign="middle"><span class="verdana_10">Rental after discounts</span></td> <td width="61" height="20" align="left" valign="middle"><span class="verdana_10">Rental after discounts <br /> X Q</span></td> <td width="40" height="20" align="left" valign="middle"> </td> </tr> <?PHP $usName = 'spires'; $client = 'tim'; $job_id = '1'; $stored_sql1 = "SELECT * FROM csv_stored WHERE stored_user='$usName' && stored_client='$client' && stored_job_id='$job_id' ORDER by stored_id ASC"; $stored_result1 = mysql_query($stored_sql1) or die ("query 2 failed".mysql_error()); $stored_count1 = mysql_num_rows($stored_result1); for ($i1 = 0; $i1<$stored_count1; $i1++){ echo ' <form name="cashFlow'.$i1.'" action="test.php" method="post"> <input name="job_id" type="hidden" value="'.$job_id.'"/> <input name="client" type="hidden" value="'.$client.'"/> <tr bgcolor="#FFFFFF" onMouseOver="this.bgColor=\'#EEEEEE\';" onMouseOut="this.bgColor=\'#FFFFFF\';">'; $stored_row1 = mysql_fetch_assoc($stored_result1); $stored_id1 = $stored_row1['stored_id']; $stored_product1 = $stored_row1['stored_product']; $stored_product_price1 = $stored_row1['stored_product_price']; $stored_item1 = $stored_row1['stored_item']; $stored_item_line_rental1 = $stored_row1['stored_item_line_rental']; $stored_unit_price1 = $stored_row1['stored_unit_price']; $stored_subtotal1 = $stored_row1['stored_subtotal']; $stored_pHandset1 = $stored_row1['stored_pHandset']; $stored_commissions1 = $stored_row1['stored_commissions']; $stored_qty1 = $stored_row1['stored_qty']; $stored_num1 = $stored_row1['stored_num']; $stored_totalMR1 = $stored_row1['totalMR']; $stored_monthly_discount1 = $stored_row1['monthly_discount']; $stored_monthly_discount_xQ1 = $stored_row1['monthly_discount_xQ']; $stored_duration1 = $stored_row1['duration']; $stored_discount_total1 = $stored_row1['discount_total']; $stored_discount_total_xQ1 = $stored_row1['discount_total_xQ']; $stored_rental_after_discount1 = $stored_row1['rental_after_discount']; $stored_rental_after_discount_xQ1 = $stored_row1['rental_after_discount_xQ']; if ($stored_product1=='add'){ $stored_product1 = 'Add to line '.$stored_num1; } $item_str1 = str_replace(' Month', 'mth', $stored_item1); $j1 = $i1+1; echo ' <td height="17" class="verdana_9" align="left"><input name="storedID2" type="hidden" value="'.$stored_id1.'" /> <input name="rowNum" type="hidden" value="'.$i1.'" /> <input name="rowCount" type="hidden" value="'.$stored_count1.'" id="rowCount" />'.$j1.'</td> <td height="17" class="verdana_9" align="left">x'.$stored_qty1.'</td> <td height="17" class="verdana_9" align="left">'.$stored_product1.'</td> <td height="17" class="verdana_9" align="left">'.$item_str1.'</td> <td height="17" class="verdana_9" align="left"><input name="STlr" type="hidden" value="'.$stored_item_line_rental1.'" id="STlr'.$i1.'" />£'.$stored_item_line_rental1.'</td> <td height="17" class="verdana_9" align="left"><input name="STmr" type="hidden" value="'.$stored_totalMR1.'" id="STmr'.$i1.'" />£'.$stored_totalMR1.'</td> <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount" type="text" size="5" class="verdana_10" height="10" value="'.$stored_monthly_discount1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';fixCashFlow(document.cashFlow'.$i1.', "mdisq", '.$stored_qty1.');" /> </td> <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount_xQ" type="text" size="5" class="verdana_10" height="10" value="'.$stored_monthly_discount_xQ1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';fixCashFlow(document.cashFlow'.$i1.', "mdis", '.$stored_qty1.');" /> </td> <td height="17" class="verdana_9" align="left"> <input name="duration" type="text" size="5" class="verdana_10" height="10" value="'.$stored_duration1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';" /> </td> <td height="17" class="verdana_9" align="left">£'.$stored_discount_total1.'</td> <td height="17" class="verdana_9" align="left">£'.$stored_discount_total_xQ1.'</td> <td height="17" class="verdana_9" align="left"> £<input name="rental_after_discount" type="text" size="5" class="verdana_10" height="10" value="'.$stored_rental_after_discount1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';fixDiscount(document.cashFlow'.$i1.', '.$stored_item_line_rental1.', '.$stored_qty1.', false);" /> </td> <td height="17" class="verdana_9" align="left"> £<input name="rental_after_discount_xQ" type="text" size="7" class="verdana_10" height="10" value="'.$stored_rental_after_discount_xQ1.'" onkeyup="this.style.backgroundColor = \'#FFCCCC\';fixDiscount(document.cashFlow'.$i1.', '.$stored_item_line_rental1.', '.$stored_qty1.', true);" /> </td> <td height="17" align="center"> <input type="submit" name="cashFlow'.$i1.'" size="10" value="update" /></td>'; echo '</tr> </form>'; } ?> </table> </body> </html>
  21. Hi guys thanks for your help, you've been great. However, I think I'm getting closer, but I have not cracked it yet. Here is the code t it's cleanest - This code works, it calculates both ways: See http://businessmobiles.com/comcalc/test.php: <script language="javascript"> var selected = 1; function calculate2() { if(selected == 1) { document.getElementById("monthly_discount_xQ" ).value=nan(document.getElementById("monthly_discount").value)*nan(document.getElementById("STqty").value); } else { document.getElementById("monthly_discount" ).value=nan(document.getElementById("monthly_discount_xQ").value)/nan(document.getElementById("STqty").value); } } function nan(value) { if(isNaN(value)) { return ""; } else { return value; } } </script> </head> <body> <form name="form1" > <input name="STqty" type="hidden" value="2" id="STqty" /> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount" type="text" size="5" class="verdana_10" height="10" value="" onchange="calculate2();" onfocus="selected = 1;" onkeyup="this.style.backgroundColor = '#FFCCCC';calculate2();" onblur="calculate2();" id="monthly_discount" /> </td> <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount_xQ" type="text" size="5" class="verdana_10" height="10" value="" onchange="calculate2();" onfocus="selected = 2;" onkeyup="this.style.backgroundColor = '#FFCCCC';calculate2();" onblur="calculate2();" id="monthly_discount_xQ"/> </td> </tr> </table> </form> See http://businessmobiles.com/comcalc/test.php: However, in the final code I need to loop through the form, creating multiple rows of the form above. This means that I need to name each form something slightly different. e.g (For loop 'i' Value) So, I think all that I need to do now is this below. But I can't get it to work. <script language="javascript"> var selected = "1a"; function calculate2() { if(selected == "1a") { document.getElementById("monthly_discount_xQ" ).value=nan(document.getElementById("monthly_discount").value)*nan(document.getElementById("STqty").value); } else { document.getElementById("monthly_discount" ).value=nan(document.getElementById("monthly_discount_xQ").value)/nan(document.getElementById("STqty").value); } } function nan(value) { if(isNaN(value)) { return ""; } else { return value; } } </script> </head> <body> <form name="form1" > <input name="STqty" type="hidden" value="2" id="STqty" /> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount" type="text" size="5" class="verdana_10" height="10" value="" onchange="calculate2();" onfocus="selected = 1a;" onkeyup="this.style.backgroundColor = '#FFCCCC';calculate2();" onblur="calculate2();" id="monthly_discount" /> </td> <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount_xQ" type="text" size="5" class="verdana_10" height="10" value="" onchange="calculate2();" onfocus="selected = 1b;" onkeyup="this.style.backgroundColor = '#FFCCCC';calculate2();" onblur="calculate2();" id="monthly_discount_xQ"/> </td> </tr> </table> </form> As you will notice, I have named 'selected' 1a and 1b. This means that I can us the for loop value of 'i' in replace of the number. E.G (ia and ib) row1 = 1a and 1b row2 = 2a and 2b row3 = 3a and 3b And then, in the JavaScript, the VAR will also be in a for loop, where I shall using: var selected = ia; and if(selected == ia) But when I try this the calculation only works one way, not both. Sorry for the long message. I hope that you could advise further Thanks
  22. Sorry, I'm new to javaScript, what do you mean by that? Thanks
  23. Hi. I have this Javascript code that I can't seem to get to work. JavaScript code: function calculate2() { var rCount=document.getElementById("rowCount").value; for(i = 0; i < rCount; i++){ var first = i; var second = i; if(first == i) { document.getElementById("monthly_discount_xQ" ).value=nan(document.getElementById("monthly_discount").value)*nan(document.getElementById("STqty").value); } else if(second == i) { document.getElementById("monthly_discount" ).value=nan(document.getElementById("monthly_discount_xQ").value)/nan(document.getElementById("STqty").value); } document.getElementById("rental_after_discount"+i).value=nan(document.getElementById("STlr"+i).value)-nan(document.getElementById("monthly_discount"+i).value); document.getElementById("rental_after_discount_xQ"+i).value=nan(document.getElementById("STmr"+i).value)-nan(document.getElementById("monthly_discount_xQ"+i).value); } } HTML & PHP: <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount" type="text" size="5" class="verdana_10" height="10" value="'.$stored_monthly_discount1.'" onchange="calculate2();" onfocus="first = '.$i1.';" onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2();" onblur="calculate2();" id="monthly_discount'.$i1.'" /> </td> <td height="17" class="verdana_9" align="left"> £<input name="monthly_discount_xQ" type="text" size="5" class="verdana_10" height="10" value="'.$stored_monthly_discount_xQ1.'" onchange="calculate2();" onfocus="second = '.$i1.';" onkeyup="this.style.backgroundColor = \'#FFCCCC\';calculate2();" onblur="calculate2();" id="monthly_discount_xQ'.$i1.'"/> </td> What I'm trying to do, is to run a calculation inside a form using javascript. However, the form has multiple rows which are being pulled from a database. This means that the amount of rows that the form has are never the same. So, I need to give each row a specific name to work, which is why I am using the value of 'i' from a for loop. However, I can seem to get this code to work. Any help, or ideas would be great Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.