Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Update a SQL DB field onchange with either onchange or ajax

Posted on 2009-05-16
7
Medium Priority
?
3,777 Views
Last Modified: 2013-12-12
Here is my question, the code below is everything however here is the important part:

          case 'PRODUCT_LIST_COST':
            $lc_align = '';
            $lc_text = ' ' . tep_draw_input_field('products_cost', $currencies->format($listing['products_cost']), 'style="width: 60px"') . ' ';
            break;


what i need to do is make this text box automatically update the associated table value, in this case products_cost, with the inputted value, what is the best/easiest way to achieve this, any help would be much appreciated.

Thanks
<?php
/*
  $Id: margin_report.php,v 3.00 2008/03/15  Exp $
  
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
 
  Copyright (c) 2003 osCommerce
  
  percentage margin per order & order status filter by mr_absinthe 2008/03/15
 
  Released under the GNU General Public License
*/
 
  require('includes/application_top.php');
 
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();
 
  class tableBox {
    var $table_border = '0';
    var $table_width = '100%';
    var $table_cellspacing = '0';
    var $table_cellpadding = '2';
    var $table_parameters = '';
    var $table_row_parameters = '';
    var $table_data_parameters = '';
 
// class constructor
    function tableBox($contents, $direct_output = false) {
      $tableBox_string = '<table border="' . tep_output_string($this->table_border) . '" width="' . tep_output_string($this->table_width) . '" cellspacing="' . tep_output_string($this->table_cellspacing) . '" cellpadding="' . tep_output_string($this->table_cellpadding) . '"';
      if (tep_not_null($this->table_parameters)) $tableBox_string .= ' ' . $this->table_parameters;
      $tableBox_string .= '>' . "\n";
 
      for ($i=0, $n=sizeof($contents); $i<$n; $i++) {
 
        if (isset($contents[$i]['form']) && tep_not_null($contents[$i]['form'])) $tableBox_string .= $contents[$i]['form'] . "\n";
		if ($i == '0') {
          $tableBox_string .= '  <tr class="dataTableHeadingRow"';
          if (tep_not_null($this->table_row_parameters)) $tableBox_string .= ' ' . $this->table_row_parameters;
          $tableBox_string .= '>' . "\n";
		} else {
          $tableBox_string .= '  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">';
		}
 
        if (isset($contents[$i][0]) && is_array($contents[$i][0])) {
          for ($x=0, $n2=sizeof($contents[$i]); $x<$n2; $x++) {
if ($i != '0') {
            if (isset($contents[$i][$x]['text']) && tep_not_null($contents[$i][$x]['text'])) {
              $tableBox_string .= '    <td class="dataTableContent"';
              if (isset($contents[$i][$x]['align']) && tep_not_null($contents[$i][$x]['align'])) $tableBox_string .= ' align="' . tep_output_string($contents[$i][$x]['align']) . '"';
			  $tableBox_string .= '>';
              if (isset($contents[$i][$x]['form']) && tep_not_null($contents[$i][$x]['form'])) $tableBox_string .= $contents[$i][$x]['form'];
              $tableBox_string .= $contents[$i][$x]['text'];
              if (isset($contents[$i][$x]['form']) && tep_not_null($contents[$i][$x]['form'])) $tableBox_string .= '</form>';
              $tableBox_string .= '</td>' . "\n";
            }
} else {
            if (isset($contents[$i][$x]['text']) && tep_not_null($contents[$i][$x]['text'])) {
              $tableBox_string .= '    <td class="dataTableHeadingContent"';
              if (isset($contents[$i][$x]['align']) && tep_not_null($contents[$i][$x]['align'])) $tableBox_string .= ' align="' . tep_output_string($contents[$i][$x]['align']) . '"';
              $tableBox_string .= '>';
              if (isset($contents[$i][$x]['form']) && tep_not_null($contents[$i][$x]['form'])) $tableBox_string .= $contents[$i][$x]['form'];
              $tableBox_string .= $contents[$i][$x]['text'];
              if (isset($contents[$i][$x]['form']) && tep_not_null($contents[$i][$x]['form'])) $tableBox_string .= '</form>';
              $tableBox_string .= '</td>' . "\n";
            }
}
          }
        } else {
if ($i != '0') {
          $tableBox_string .= '    <td class="dataTableContent">' . $contents[$i]['text'] . '</td>' . "\n";
} else {
          $tableBox_string .= '    <td';
          if (isset($contents[$i]['align']) && tep_not_null($contents[$i]['align'])) $tableBox_string .= ' align="' . tep_output_string($contents[$i]['align']) . '"';
          if (isset($contents[$i]['params']) && tep_not_null($contents[$i]['params'])) {
            $tableBox_string .= ' ' . $contents[$i]['params'];
          } elseif (tep_not_null($this->table_data_parameters)) {
            $tableBox_string .= ' ' . $this->table_data_parameters;
          }
          $tableBox_string .= '>' . $contents[$i]['text'] . '</td>' . "\n";
}
        }
 
        $tableBox_string .= '  </tr>' . "\n";
        if (isset($contents[$i]['form']) && tep_not_null($contents[$i]['form'])) $tableBox_string .= '</form>' . "\n";
      }
 
      $tableBox_string .= '</table>' . "\n";
 
      if ($direct_output == true) echo $tableBox_string;
 
      return $tableBox_string;
    }
  }
 
  class productListingBox extends tableBox {
    function productListingBox($contents) {
      $this->tableBox($contents, true);
    }
  }
 
  class splitPageResults2 {
    var $sql_query, $number_of_rows, $current_page_number, $number_of_pages, $number_of_rows_per_page, $page_name;
 
/* class constructor */
    function splitPageResults2($query, $max_rows, $count_key = '*', $page_holder = 'page') {
      global $_GET, $HTTP_POST_VARS;
 
      $this->sql_query = $query;
      $this->page_name = $page_holder;
 
      if (isset($_GET[$page_holder])) {
        $page = $_GET[$page_holder];
      } elseif (isset($HTTP_POST_VARS[$page_holder])) {
        $page = $HTTP_POST_VARS[$page_holder];
      } else {
        $page = '';
      }
 
      if (empty($page) || !is_numeric($page)) $page = 1;
      $this->current_page_number = $page;
 
      $this->number_of_rows_per_page = $max_rows;
 
      $pos_to = strlen($this->sql_query);
      $pos_from = strpos($this->sql_query, ' from', 0);
 
      $pos_group_by = strpos($this->sql_query, ' group by', $pos_from);
      if (($pos_group_by < $pos_to) && ($pos_group_by != false)) $pos_to = $pos_group_by;
 
      $pos_having = strpos($this->sql_query, ' having', $pos_from);
      if (($pos_having < $pos_to) && ($pos_having != false)) $pos_to = $pos_having;
 
      $pos_order_by = strpos($this->sql_query, ' order by', $pos_from);
      if (($pos_order_by < $pos_to) && ($pos_order_by != false)) $pos_to = $pos_order_by;
 
      if (strpos($this->sql_query, 'distinct') || strpos($this->sql_query, 'group by')) {
        $count_string = 'distinct ' . tep_db_input($count_key);
      } else {
        $count_string = tep_db_input($count_key);
      }
 
      $count_query = tep_db_query("select count(" . $count_string . ") as total " . substr($this->sql_query, $pos_from, ($pos_to - $pos_from)));
      $count = tep_db_fetch_array($count_query);
 
      $this->number_of_rows = $count['total'];
 
      $this->number_of_pages = ceil($this->number_of_rows / $this->number_of_rows_per_page);
 
      if ($this->current_page_number > $this->number_of_pages) {
        $this->current_page_number = $this->number_of_pages;
      }
 
      $offset = ($this->number_of_rows_per_page * ($this->current_page_number - 1));
 
      $this->sql_query .= " limit " . $offset . ", " . $this->number_of_rows_per_page;
    }
 
// display split-page-number-links
    function display_links2($max_page_links, $parameters = '') {
      global $PHP_SELF, $request_type;
	  $request_type='NONSSL';
 
      $display_links_string = '';
 
      $class = 'class="pageResults"';
 
      if (tep_not_null($parameters) && (substr($parameters, -1) != '&')) $parameters .= '&';
 
// previous button - not displayed on first page
      if ($this->current_page_number > 1) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . ($this->current_page_number - 1), $request_type) . '" class="pageResults" title=" ' . PREVNEXT_TITLE_PREVIOUS_PAGE . ' "><u>' . PREVNEXT_BUTTON_PREV . '</u></a>&nbsp;&nbsp;';
 
// check if number_of_pages > $max_page_links
      $cur_window_num = intval($this->current_page_number / $max_page_links);
      if ($this->current_page_number % $max_page_links) $cur_window_num++;
 
      $max_window_num = intval($this->number_of_pages / $max_page_links);
      if ($this->number_of_pages % $max_page_links) $max_window_num++;
 
// previous window of pages
      if ($cur_window_num > 1) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . (($cur_window_num - 1) * $max_page_links), $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a>';
 
// page nn button
      for ($jump_to_page = 1 + (($cur_window_num - 1) * $max_page_links); ($jump_to_page <= ($cur_window_num * $max_page_links)) && ($jump_to_page <= $this->number_of_pages); $jump_to_page++) {
        if ($jump_to_page == $this->current_page_number) {
          $display_links_string .= '&nbsp;<b>' . $jump_to_page . '</b>&nbsp;';
        } else {
          $display_links_string .= '&nbsp;<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . $jump_to_page, $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_PAGE_NO, $jump_to_page) . ' "><u>' . $jump_to_page . '</u></a>&nbsp;';
        }
      }
 
// next window of pages
      if ($cur_window_num < $max_window_num) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . (($cur_window_num) * $max_page_links + 1), $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a>&nbsp;';
 
// next button
      if (($this->current_page_number < $this->number_of_pages) && ($this->number_of_pages != 1)) $display_links_string .= '&nbsp;<a href="' . tep_href_link(basename($PHP_SELF), $parameters . 'page=' . ($this->current_page_number + 1), $request_type) . '" class="pageResults" title=" ' . PREVNEXT_TITLE_NEXT_PAGE . ' "><u>' . PREVNEXT_BUTTON_NEXT . '</u></a>&nbsp;';
 
      return $display_links_string;
    }
 
    function display_count2($text_output) {
      $to_num = ($this->number_of_rows_per_page * $this->current_page_number);
      if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows;
 
      $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1));
 
      if ($to_num == 0) {
        $from_num = 0;
      } else {
        $from_num++;
      }
 
      return sprintf($text_output, $from_num, $to_num, $this->number_of_rows);
    }
  }
 
// Return table heading with sorting capabilities
  function tep_create_sort_heading($sortby, $colnum, $heading) {
    global $PHP_SELF;
 
    $sort_prefix = '';
    $sort_suffix = '';
 
    if ($sortby) {
      $sort_prefix = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('page', 'info', 'sort')) . 'page=1&sort=' . $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a')) . '" title="' . tep_output_string(TEXT_SORT_PRODUCTS . ($sortby == $colnum . 'd' || substr($sortby, 0, 1) != $colnum ? TEXT_ASCENDINGLY : TEXT_DESCENDINGLY) . TEXT_BY . $heading) . '">' ;
      $sort_suffix = (substr($sortby, 0, 1) == $colnum ? (substr($sortby, 1, 1) == 'a' ? '+' : '-') : '') . '</a>';
    }
 
    return $sort_prefix . $heading . $sort_suffix;
  }
 
  if ((isset($_GET['action'])) && ($_GET['action'] == 'export')) {
 
	if (isset($_GET['manufacturers_id']) && ($_GET['manufacturers_id'] != '') && (!isset($_GET['filter_id']))) {
	  $manufacturer_query = tep_db_query("select manufacturers_name as name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . $_GET['manufacturers_id'] . "'");
	  $manufacturer = tep_db_query($manufacturer_query);
	  $xls_header = 'Margin Report: ' . $manufacturer['name'];
	} elseif (isset($_GET['manufacturers_id']) && ($_GET['manufacturers_id'] != '') && (isset($_GET['filter_id']) && ($_GET['filter_id'] != ''))) {
	  $manufacturer_query = tep_db_query("select manufacturers_name as name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . $_GET['manufacturers_id'] . "'");
	  $manufacturer = tep_db_fetch_array($manufacturer_query);
	  $category_query = tep_db_query("select categories_name as name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $_GET['filter_id'] . "'");
	  $category = tep_db_fetch_array($category_query);
	  $xls_header = 'Margin Report: ' . $manufacturer['name'] . ' - ' . $category['name'];
	} else {
	  $xls_header = 'Margin Report: All Products';
	  }
 
	$sql = stripslashes($_GET['sql']);
	//echo $sql;
	$csv_query = mysql_query($sql);
 
$xls .= '<table width="1050" border="1" cellspacing="0" cellpadding="2">
  <tr align="center">
    <td colspan="6" width="1050" bgcolor="#FFFF00">
      <font face="Arial, Helvetica, sans-serif"><strong>' . $xls_header. '
        </strong> </font>    
    </td>
  </tr>
  <tr>
    <td colspan="6"> </td>
  </tr>
  <tr>
    <td width="250" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_PRODUCTS_NAME .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_PRODUCTS_COST .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_PRODUCTS_COST2 .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_PRODUCTS_COST3 .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_PRODUCTS_COST4 .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_PRODUCTS_COST5 .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_PRODUCTS_COST6 .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_PRODUCTS_PRICE .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_SPECIAL_PRICE .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_MARGIN_MONEY .'</em></font>    
    </td>
    <td width="160" align="right" bgcolor="#00CCFF">
    <font size="4" face="Times New Roman, Times, serif"><em>'. TEXT_MARGIN_PERCENTAGE .'</em></font>    
    </td>
  </tr>';
 
$a = '1';
while ($csv_results = tep_db_fetch_array($csv_query)) {
  if ($a == '1') {
	if ($csv_results['specials_price'] == '' || $csv_results['specials_price'] == 'NULL') {
	  $xls .= '<tr><td bgcolor="#C0C0C0">' . tep_get_products_name($csv_results['products_id']) . '</td><td bgcolor="#C0C0C0">' .$currencies->format($csv_results['products_cost']) . '</td><td bgcolor="#C0C0C0">' . $currencies->format($csv_results['products_price']) . '</td><td bgcolor="#C0C0C0"> </td><td bgcolor="#C0C0C0">' . $currencies->format($csv_results['margin_dollars']) . '</td><td bgcolor="#C0C0C0">' . number_format($csv_results['margin_percentage'], '2', '.', ',') . '</td></tr>';
	} else {
	  $xls .= '<tr><td bgcolor="#C0C0C0">' . tep_get_products_name($csv_results['products_id']) . '</td><td bgcolor="#C0C0C0">' .$currencies->format($csv_results['products_cost']) . '</td><td bgcolor="#C0C0C0">' . $currencies->format($csv_results['products_price']) . '</td><td bgcolor="#C0C0C0">' . $currencies->format($csv_results['specials_price']) . '</td><td bgcolor="#C0C0C0">' . $currencies->format($csv_results['margin_dollars']) . '</td><td bgcolor="#C0C0C0">' . number_format($csv_results['margin_percentage'], '2', '.', ',') . '</td></tr>';
	}
	$a='0';
  } else {
	if ($csv_results['specials_price'] == '' || $csv_results['specials_price'] == 'NULL') {
	  $xls .= '<tr><td bgcolor="#969696">' . tep_get_products_name($csv_results['products_id']) . '</td><td bgcolor="#969696">' .$currencies->format($csv_results['products_cost']) . '</td><td bgcolor="#969696">' . $currencies->format($csv_results['products_price']) . '</td><td bgcolor="#969696"> </td><td bgcolor="#969696">' . $currencies->format($csv_results['margin_dollars']) . '</td><td bgcolor="#969696">' . number_format($csv_results['margin_percentage'], '2', '.', ',') . '</td></tr>';
	} else {
	  $xls .= '<tr><td bgcolor="#969696">' . tep_get_products_name($csv_results['products_id']) . '</td><td bgcolor="#969696">' .$currencies->format($csv_results['products_cost']) . '</td><td bgcolor="#969696">' . $currencies->format($csv_results['products_price']) . '</td><td bgcolor="#969696">' . $currencies->format($csv_results['specials_price']) . '</td><td bgcolor="#969696">' . $currencies->format($csv_results['margin_dollars']) . '</td><td bgcolor="#969696">' . number_format($csv_results['margin_percentage'], '2', '.', ',') . '</td></tr>';
	}
	$a='1';
  }
}
$xls .= '<tr>
    <td colspan="6"> </td>
  </tr>
  <tr>
    <td colspan="6" align="center"><font size="4" face="Times New Roman, Times, serif">This report was generated by Margin Report. An <a href="http://www.eclyptiq.com">Eclyptiq</a> contribution for osCommerce ms2.2.</font></td>
  </tr>
</table>';
/////////////////////////////////////////////////////////////////////////////////
 
if ((isset($_GET['file'])) && ($_GET['file'] != '') && ($_GET['file'] != 'example_filename')) {
//////////////////////////////////////////////////////////////
// Please change this to the folder you want to use.
$extension = '.xls';
//////////////////////////////////////////////////////////////
$filename = $_GET['file'] . $extension;
 
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $filename);
header("Pragma: no-cache");
header("Expires: 0");
print "$xls";
exit();
 
} else {
echo 'Please enter a valid filename and check your location.';
}
}
//////////////////////////////////////////////////////////////////////////////////
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
 
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
<?php
      if (isset($_GET['manufacturers_id'])) {
        $filterlist_sql = "select distinct c.categories_id as id, cd.categories_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where p.products_status = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p2c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "' order by cd.categories_name";
	  } else {
        $filterlist_sql= "select distinct m.manufacturers_id as id, m.manufacturers_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and p.products_id = p2c.products_id order by m.manufacturers_name";
      }
      $filterlist_query = tep_db_query($filterlist_sql);
  
      if (tep_db_num_rows($filterlist_query) > 1) {
        echo '            <td align="right" class="main">' . tep_draw_form('filter', FILENAME_MARGIN_REPORT, '', 'get') . TEXT_SHOW . '&nbsp;';
        if (isset($_GET['manufacturers_id'])) {
          echo tep_draw_hidden_field('manufacturers_id', $_GET['manufacturers_id']);
          $options = array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES_BY_MANUFACTURER));
        } else {
          echo tep_draw_hidden_field('cPath', $cPath);
          $options = array(array('id' => '', 'text' => TEXT_ALL_MANUFACTURERS));
        }
        echo tep_draw_hidden_field('sort', $_GET['sort']);
        while ($filterlist = tep_db_fetch_array($filterlist_query)) {
          $options[] = array('id' => $filterlist['id'], 'text' => $filterlist['name']);
        }
        if (!isset($_GET['manufacturers_id'])) echo tep_draw_pull_down_menu('manufacturers_id', $options, (isset($_GET['filter_id']) ? $_GET['filter_id'] : ''), 'onchange="this.form.submit()"');
        if (isset($_GET['manufacturers_id'])) echo tep_draw_pull_down_menu('filter_id', $options, (isset($_GET['filter_id']) ? $_GET['filter_id'] : ''), 'onchange="this.form.submit()"');
        echo '</form></td>' . "\n";
      }
?>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top">
<?php
    $define_list = array('PRODUCT_LIST_PRODUCT' => '1',
                         'PRODUCT_LIST_COST' => '2',
                         'PRODUCT_LIST_COST2' => '3',
                         'PRODUCT_LIST_COST3' => '4',
                         'PRODUCT_LIST_COST4' => '5',
                         'PRODUCT_LIST_COST5' => '6',
                         'PRODUCT_LIST_COST6' => '7',
                         'PRODUCT_LIST_PRICE' => '8',
                         'PRODUCT_LIST_SPECIAL_PRICE' => '9',
                         'PRODUCT_LIST_MARGIN_DOLLARS' => '10',
                         'PRODUCT_LIST_MARGIN_PERCENTAGE' => '11');
 
    asort($define_list);
    $column_list = array();
    reset($define_list);
    while (list($key, $value) = each($define_list)) {
      if ($value > 0) $column_list[] = $key;
    }
	
// show the products of a specified manufacturer
    if (isset($_GET['manufacturers_id'])) {
      if (isset($_GET['filter_id']) && tep_not_null($_GET['filter_id'])) {
// We are asked to show only a specific category
        $listing_sql = "select p.products_id, p.products_price as products_price, p.products_cost, p.products_cost2, p.products_cost3, p.products_cost4, p.products_cost5, p.products_cost6, p.products_model, IF(s.status, s.specials_new_products_price, NULL) as specials_price, if(s.status, s.specials_new_products_price-p.products_cost, p.products_price-p.products_cost) as margin_dollars, if(s.status, (s.specials_new_products_price-p.products_cost)/s.specials_new_products_price*100, (p.products_price-p.products_cost)/p.products_price*100) as margin_percentage, p2c.categories_id as category, c.parent_id as parent from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where pd.language_id = '" . (int)$languages_id . "' and p.products_id = pd.products_id and p2c.products_id = p.products_id and c.categories_id = p2c.categories_id and p2c.categories_id = '" . (int)$_GET['filter_id'] . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "'";
      } else {
// We show them all
        $listing_sql = "select p.products_id, p.products_price as products_price, p.products_cost, p.products_cost2, p.products_cost3, p.products_cost4, p.products_cost5, p.products_cost6, p.products_model, IF(s.status, s.specials_new_products_price, NULL) as specials_price, if(s.status, s.specials_new_products_price-p.products_cost, p.products_price-p.products_cost) as margin_dollars, if(s.status, (s.specials_new_products_price-p.products_cost)/s.specials_new_products_price*100, (p.products_price-p.products_cost)/p.products_price*100) as margin_percentage, p2c.categories_id as category, c.parent_id as parent from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where pd.language_id = '" . (int)$languages_id . "' and p.products_id = pd.products_id and p2c.products_id = p.products_id and c.categories_id = p2c.categories_id and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "'";
      }
    } elseif (isset($_GET['filter_id']) && tep_not_null($_GET['filter_id'])) {
// show the products in a given category
// We are asked to show only specific category
        $listing_sql = "select p.products_id, p.products_price as products_price, p.products_cost, p.products_cost2, p.products_cost3, p.products_cost4, p.products_cost5, p.products_cost6, p.products_model, IF(s.status, s.specials_new_products_price, NULL) as specials_price, if(s.status, s.specials_new_products_price-p.products_cost, p.products_price-p.products_cost) as margin_dollars, if(s.status, (s.specials_new_products_price-p.products_cost)/s.specials_new_products_price*100, (p.products_price-p.products_cost)/p.products_price*100) as margin_percentage, p2c.categories_id as category, c.parent_id as parent from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where pd.language_id = '" . (int)$languages_id . "' and p.products_id = pd.products_id and p2c.products_id = p.products_id and c.categories_id = p2c.categories_id and p2c.categories_id = '" . (int)$_GET['filter_id'] . "'";
    } elseif (isset($_GET['report_id']) && tep_not_null($_GET['report_id'])) {
// Show the products from the time frame defined by the report variable.
      $listing_sql = "select p.products_id, p.products_price as products_price, p.products_cost, p.products_cost2, p.products_cost3, p.products_cost4, p.products_cost5, p.products_cost6, p.products_model, IF(s.status, s.specials_new_products_price, NULL) as specials_price, if(s.status, s.specials_new_products_price-p.products_cost, p.products_price-p.products_cost) as margin_dollars, if(s.status, (s.specials_new_products_price-p.products_cost)/s.specials_new_products_price*100, (p.products_price-p.products_cost)/p.products_price*100) as margin_percentage, p2c.categories_id as category, c.parent_id as parent from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where pd.language_id = '" . (int)$languages_id . "' and p.products_id = pd.products_id and p2c.products_id = p.products_id and c.categories_id = p2c.categories_id and p2c.categories_id = '" . (int)$_GET['filter_id'] . "'";
    } else {
// We show them all
        $listing_sql = "select " . $select_column_list . " p.products_id, p.products_price as products_price, p.products_cost, p.products_cost2, p.products_cost3, p.products_cost4, p.products_cost5, p.products_cost6, p.products_model, IF(s.status, s.specials_new_products_price, NULL) as specials_price, if(s.status, s.specials_new_products_price-p.products_cost, p.products_price-p.products_cost) as margin_dollars, if(s.status, (s.specials_new_products_price-p.products_cost)/s.specials_new_products_price*100, (p.products_price-p.products_cost)/p.products_price*100) as margin_percentage, p2c.categories_id as category, c.parent_id as parent from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where pd.language_id = '" . (int)$languages_id . "' and p.products_id = pd.products_id and p2c.products_id = p.products_id and c.categories_id = p2c.categories_id";
}	
 
    if ( (!isset($_GET['sort'])) || (!ereg('[1-8][ad]', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) {
      for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
        if ($column_list[$i] == 'PRODUCT_LIST_PRODUCT') {
          $_GET['sort'] = $i+1 . 'a';
          $listing_sql .= " order by p.products_model";
          break;
        }
      }
    } else {
      $sort_col = substr($_GET['sort'], 0 , 1);
      $sort_order = substr($_GET['sort'], 1);
      $listing_sql .= ' order by ';
      switch ($column_list[$sort_col-1]) {
        case 'PRODUCT_LIST_PRODUCT':
          $listing_sql .= "p.products_model " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_COST':
          $listing_sql .= "p.products_cost " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_COST2':
          $listing_sql .= "p.products_cost2 " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_COST3':
          $listing_sql .= "p.products_cost3 " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_COST4':
          $listing_sql .= "p.products_cost4 " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_COST5':
          $listing_sql .= "p.products_cost5 " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_COST6':
          $listing_sql .= "p.products_cost6 " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_PRICE':
          $listing_sql .= "p.products_price " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_SPECIAL_PRICE':
          $listing_sql .= "specials_price " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_MARGIN_DOLLARS':
          $listing_sql .= "margin_dollars " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_MARGIN_PERCENTAGE':
          $listing_sql .= "margin_percentage " . ($sort_order == 'd' ? 'desc' : '');
          break;
      }
    }
 
 
  $listing_split = new splitPageResults2($listing_sql, MAX_DISPLAY_SEARCH_RESULTS);
 
  if (($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
 
?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
  <tr>
    <td class="smallText"><?php echo $listing_split->display_count2(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
    <td class="smallText" align="right"><?php echo TEXT_RESULT_PAGES . ' ' . $listing_split->display_links2(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('info', 'x', 'y'))); ?></td>
  </tr>
</table>
<?php
  }
 
  $list_box_contents = array();
 
  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    switch ($column_list[$col]) {
      case 'PRODUCT_LIST_PRODUCT':
        $lc_text = TABLE_HEADING_PRODUCT;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_COST':
        $lc_text = TABLE_HEADING_COST;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_COST2':
        $lc_text = TABLE_HEADING_COST2;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_COST3':
        $lc_text = TABLE_HEADING_COST3;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_COST4':
        $lc_text = TABLE_HEADING_COST4;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_COST5':
        $lc_text = TABLE_HEADING_COST5;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_COST6':
        $lc_text = TABLE_HEADING_COST6;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_PRICE':
        $lc_text = TABLE_HEADING_PRICE;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_SPECIAL_PRICE':
        $lc_text = TABLE_HEADING_SPECIAL_PRICE;
        $lc_align = 'right';
        break;
      case 'PRODUCT_LIST_MARGIN_DOLLARS':
        $lc_text = TABLE_HEADING_MARGIN_DOLLARS;
        $lc_align = 'right';
        break;
      case 'PRODUCT_LIST_MARGIN_PERCENTAGE':
        $lc_text = TABLE_HEADING_MARGIN_PERCENTAGE;
        $lc_align = 'right';
        break;
    }
 
      $lc_text = tep_create_sort_heading($_GET['sort'], $col+1, $lc_text);
 
 
    $list_box_contents[0][] = array('align' => $lc_align,
                                    'params' => 'class="dataTableHeadingRow"',
                                    'text' => '&nbsp;' . $lc_text . '&nbsp;');
  }
 
  if ($listing_split->number_of_rows > 0) {
    $rows = 0;
    $listing_query = tep_db_query($listing_split->sql_query);
    while ($listing = tep_db_fetch_array($listing_query)) {
      $rows++;
 
      if (($rows/2) == floor($rows/2)) {
        $list_box_contents[] = array('params' => 'class="dataTableContent"');
      } else {
        $list_box_contents[] = array('params' => 'class="dataTableContent"');
      }
 
      $cur_row = sizeof($list_box_contents) - 1;
 
      for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
        $lc_align = '';
 
        switch ($column_list[$col]) {
          case 'PRODUCT_LIST_PRODUCT':
            $lc_align = '';
            if ($listing['parent'] == '0') {
			$lc_text = '&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $listing['category'] . '&pID=' . $listing['products_id'] . '&action=new_product') . '">' . $listing['products_model'] . '</a>&nbsp;';
			} else {
			$lc_text = '&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $listing['parent'] . '_' . $listing['category'] . '&pID=' . $listing['products_id'] . '&action=new_product') . '">' . $listing['products_model'] . '</a>&nbsp;';
			}
            break;
 
          case 'PRODUCT_LIST_COST':
            $lc_align = '';
            $lc_text = '&nbsp;' . tep_draw_input_field('products_cost', $currencies->format($listing['products_cost']), 'style="width: 60px"') . '&nbsp;';
            break;
          case 'PRODUCT_LIST_COST2':
            $lc_align = '';
            $lc_text = '&nbsp;' . tep_draw_input_field('products_cost2', $currencies->format($listing['products_cost2']), 'style="width: 60px"') . '&nbsp;';
            break;
          case 'PRODUCT_LIST_COST3':
            $lc_align = '';
            $lc_text = '&nbsp;' . tep_draw_input_field('products_cost3', $currencies->format($listing['products_cost3']), 'style="width: 60px"') . '&nbsp;';
            break;
          case 'PRODUCT_LIST_COST4':
            $lc_align = '';
            $lc_text = '&nbsp;' . tep_draw_input_field('products_cost4', $currencies->format($listing['products_cost4']), 'style="width: 60px"') . '&nbsp;';
            break;
          case 'PRODUCT_LIST_COST5':
            $lc_align = '';
            $lc_text = '&nbsp;' . tep_draw_input_field('products_cost5', $currencies->format($listing['products_cost5']), 'style="width: 60px"') . '&nbsp;';
            break;
          case 'PRODUCT_LIST_COST6':
            $lc_align = '';
            $lc_text = '&nbsp;' . tep_draw_input_field('products_cost6', $currencies->format($listing['products_cost6']), 'style="width: 60px"') . '&nbsp;';
            break;
          case 'PRODUCT_LIST_PRICE':
            $lc_align = '';
            if (tep_not_null($listing['specials_price'])) {
              $lc_text = '&nbsp;<s>' . $currencies->format($listing['products_price']) . '&nbsp;';
            } else {
              $lc_text = '&nbsp;' . $currencies->format($listing['products_price']) . '&nbsp;';
            }
            break;
          case 'PRODUCT_LIST_SPECIAL_PRICE':
            $lc_align = 'right';
            if (tep_not_null($listing['specials_price'])) {
              $lc_text = '&nbsp;' . '<span class="specialprice">' . $currencies->format($listing['specials_price']) . '</span>&nbsp;';
            } else {
              $lc_text = '&nbsp;' . ' ' . '&nbsp;';
            }
            break;
          case 'PRODUCT_LIST_MARGIN_DOLLARS':
            $lc_align = 'right';
			if ($listing['products_price'] > $listing['products_cost']) {
			$lc_text = '&nbsp;' . $currencies->format($listing['margin_dollars']) . '&nbsp;';
			} else {
			$lc_text = '&nbsp;' . '<span class="belowCost">' . $currencies->format($listing['margin_dollars']) . '</span>' . '&nbsp;';
			}
            break;
          case 'PRODUCT_LIST_MARGIN_PERCENTAGE':
            $lc_align = 'right';
			if ($listing['products_price'] > $listing['products_cost']) {
            $lc_text = '&nbsp;' . number_format($listing['margin_percentage'], '2', '.', ',') . '%' . '&nbsp;';
			} else {
			$lc_text = '&nbsp;' . '<span class="belowCost">' . number_format($listing['margin_percentage'], '2', '.', ',') . '%</span>' . '&nbsp;';
			}
            break;
        }
 
        $list_box_contents[$cur_row][] = array('align' => $lc_align,
                                               'params' => 'class="dataTableRow"',
                                               'text'  => $lc_text);
      }
    }
 
    new productListingBox($list_box_contents);
  } else {
    $list_box_contents = array();
 
    $list_box_contents[0] = array('params' => 'class="productListing-odd"');
    $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                   'text' => TEXT_NO_PRODUCTS);
                                   
    new productListingBox($list_box_contents);
  }
 
  if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
  <tr>
    <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
  </tr>
  <tr>
    <td class="smallText"><?php echo $listing_split->display_count2(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
    <td class="smallText" align="right"><?php echo TEXT_RESULT_PAGES . ' ' . $listing_split->display_links2(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('info', 'x', 'y'))); ?></td>
  </tr>
</table>
<?php
  }
?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
  <tr>
       		  <?php if (isset($_GET['manufacturers_id'])) { ?>
				<td align="left"><?php echo '<a href="' . tep_href_link(FILENAME_MARGIN_REPORT, '', 'NONSSL') . '">' . tep_image_button('button_back.gif', BUTTON_BACK_TO_MAIN) . '</a>'; ?></td>
			  <?php } else { 
 
        echo '<td align="left" class="main">' . tep_draw_form('report', FILENAME_MARGIN_REPORT2, '', 'get') . TEXT_SHOW . '&nbsp;';
          $options = array();
	    $options[] = array('id' => 'all', 'text' => TEXT_SELECT_REPORT);
          $options[] = array('id' => 'daily', 'text' => TEXT_SELECT_REPORT_DAILY);
          $options[] = array('id' => 'yesterday', 'text' => TEXT_SELECT_REPORT_YESTERDAY);
          $options[] = array('id' => 'weekly', 'text' => TEXT_SELECT_REPORT_WEEKLY);
          $options[] = array('id' => 'lastweek', 'text' => TEXT_SELECT_REPORT_LASTWEEK);
          $options[] = array('id' => 'monthly', 'text' => TEXT_SELECT_REPORT_MONTHLY);
          $options[] = array('id' => 'lastmonth', 'text' => TEXT_SELECT_REPORT_LASTMONTH);
          $options[] = array('id' => 'quarterly', 'text' => TEXT_SELECT_REPORT_QUARTERLY);
          $options[] = array('id' => 'semiannually', 'text' => TEXT_SELECT_REPORT_SEMIANNUALLY);
          $options[] = array('id' => 'annually', 'text' => TEXT_SELECT_REPORT_ANNUALLY);
        echo tep_draw_pull_down_menu('report_id', $options, (isset($_GET['report_id']) ? $_GET['report_id'] : '1'), 'onchange="this.form.submit()"');
        echo '</form></td>' . "\n";
      }
 
  if (isset($_GET['manufacturers_id']) && ($_GET['manufacturers_id'] != '') && (!isset($_GET['filter_id']))) {
	$get_vars = tep_draw_hidden_field('manufacturers_id', $_GET['manufacturers_id']);
  } elseif (isset($_GET['manufacturers_id']) && ($_GET['manufacturers_id'] != '') && (isset($_GET['filter_id']) && ($_GET['filter_id'] != ''))) {
	$get_vars = tep_draw_hidden_field('manufacturers_id', $_GET['manufacturers_id']) . tep_draw_hidden_field('filter_id', $_GET['filter_id']);
  } else {
	$get_vars = '';
	}
 
?>
		      <td align="right"><table><tr><td><?php echo tep_draw_form('export_to_file', FILENAME_MARGIN_REPORT, 'get', '') . tep_draw_hidden_field('action', 'export') . $get_vars . tep_draw_hidden_field('sql', $listing_sql); ?><input type="text" name="file" value="example_filename" onfocus="javascript:if(this.value=='example_filename') {this.value='';}" onblur="javascript:if(this.value=='') {this.value='example_filename'}"></td><td><?php echo '<input type="image" name="submit" src="' . DIR_WS_LANGUAGES . $language . '/images/buttons/button_export.gif" alt="' . TEXT_EXPORT_BUTTON . '" width="65" height="22"></form>'; ?></td></tr></table></td>
		  </tr>
        </table>
		</td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->
 
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Open in new window

0
Comment
Question by:EliteViper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24404035
Wow! 734 lines of code?  It looks like the "important part" is near line 597.

Is it possible to tell us a little more?  When you say, "make this text box automatically update the associated table value" - are you talking about an HTML table or a database table?  Where does the inputted value come from?
0
 

Author Comment

by:EliteViper
ID: 24404348
lol yes i know a little too many lines but well whats happening is as you might be able to tell its actually very simple, the value comes from the table in the database and well as far as its origin, it will originate from this page however technically its created when a product is created however employees are making the products and will not have access to the costs so when the product is created then product_cost, product_cost2, product_cost3... will all have a default value of 0.00 and well then the point of this page will be to actually give these fields real cost values for example... heres what the page looks like and its perfect the way it looks..(see attached file) however changing the values does nothing and well i would like to have it when i enter the first value then press tab going to the next box that the value i just evtered updates accordingly in the DB.

hope that helps

Thanks :)
example.jpg
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 24407123
OK, if you want to update the data base every time the tab is depressed, you will need an AJAX-type application.  This code snippet teaches the general principles of AJAX.  I do not know where i got it originally but since it is signed "Rasmus" it might be "Lerdorf" of PHP fame.  It shows how to send the AJAX request when a link is clicked.  I will look for something that shows how to recognize a tab key.
I find a lot of this AJAX stuff a bit of a hype.  Lots of people have
been using similar things long before it became "AJAX".  And it really
isn't as complicated as a lot of people make it out to be.  Here is a
simple example from one of my apps.  
 
/* THE JAVASCRIPT TO CREATE THE AJAX INFRASTRUCTURE */
/* FUNCTION TO CREATE THE BROWSER-DEPENDENT REQUEST OBJECT */
function createRequestObject() 
{
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer")
    {
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else
    {
        ro = new XMLHttpRequest();
    }
    return ro;
}
 
 
/* FUNCTION TO SEND THE REQUEST */
function sendReq(action) 
{
    http.open('get', 'ajaxprocessor.php?action='+action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
 
 
/* FUNCTION TO HANDLE THE RESPONSE */
function handleResponse()
{
    if(http.readyState == 4)
    {
        var response = http.responseText;
        var update = new Array();
 
        if(response.indexOf('|' != -1))
        {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}
 
 
/* CREATE THE OBJECT */
var http = createRequestObject();
 
/* END OF THE JAVASCRIPT */
 
This creates a request object along with a send request and handle
response function.  So to actually use it, you could include this js in
your page.  Then to make one of these backend requests you would tie it
to something.  Like an onclick event or a straight href like this:
 
<a href="javascript:sendReq('foo')">[Foo]</a>
 
That means that when someone clicks on that link what actually happens
is that a backend request to ajaxprocessor.php?action=foo will be sent.
 
In ajaxprocessor.php you might have something like this:
 
/* THE PHP TO HANDLE THE REQUEST FROM THE FRONT-END SCRIPT */
switch($_GET['action']) 
{
    case 'foo':
      // DO WHATEVER PROCESSING IS APPROPRIATE
      // THEN RETURN A RESPONSE STRING TO handleResponse()
      echo "foo|Foo done";
      break;
      // ETC...
}
 
Now, look at handleResponse.  It parses the "foo|Foo done" string and
splits it on the '|' and uses whatever is before the '|' as the dom
element id in your page and the part after as the new innerHTML of that
element.  That means if you have a div tag like this in your page:
 
<div id="foo">Waiting for Foo</div>
 
Once you click on that link, that will dynamically be changed to:
 
<div id="foo">Foo done</div>
 
That's all there is to it.  Everything else is just building on top of
this.  Replacing my simple response "id|text" syntax with a richer XML
format and making the request much more complicated as well.  Before you
blindly install large "AJAX" libraries, have a go at rolling your own
functionality so you know exactly how it works and you only make it as
complicated as you need.  Often you do not need much more than what I
have shown here.
 
Expanding this approach a bit to send multiple parameters in the
request, for example, would be really simple.  Something like:
 
function sendReqArg(action,arg) 
{
    http.open('get', 'ajaxprocessor.php?action='+action+'&arg='+arg);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
 
And your handleResponse can easily be expanded to do more interesting 
things than just replacing the contents of a div.
 
-Rasmus (Lerdorf?)

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24407197
Reading some of the literature, I think you want to fire your AJAX request when the field loses focus.  There are many ways that can happen, not just the tab key.  Some possibly useful links here:

http://www.codeproject.com/KB/dialog/TabKeyIntercept.aspx
http://www.yaldex.com/FSForms/TabKeyEmulation.htm
http://www.cs.tut.fi/~jkorpela/forms/tabbing.html

Best of luck with it, ~Ray
0
 

Author Closing Comment

by:EliteViper
ID: 31582264
Though im not using this exact solution it gave me the tools needed to figure out exactly what i needed :) thanks and i have a few more which im sure answers will be able to be found here :)
0
 

Author Comment

by:EliteViper
ID: 24410595
So now the update works in 1 place perfectly however ... i now need to convert this:

              <td class="dataTableContent" valign="top"><input name="<?php echo "update_products[" . $orders_products_id . "][cost]"; ?>" size="7" <?php if (ORDER_EDITOR_USE_AJAX == 'true') { ?>onChange="updateProductsField('update', '<?php echo $orders_products_id; ?>', 'products_cost', encodeURIComponent(this.value))"<?php } ?> value="<?php echo $order->products[$i]['cost']; ?>"></td>

to be used in this:

          case 'PRODUCT_LIST_COST':
            $lc_align = '';
            $lc_text = '&nbsp;' . tep_draw_input_field('products_cost', $currencies->format($listing['products_cost']), 'style="width: 60px"') . '&nbsp;';
            break;


i hate case things and $lc_text because i honestly don't know how to use them correctly.
0
 

Author Comment

by:EliteViper
ID: 24410671
I think i need something like this:

            $lc_text = '&nbsp;' . tep_draw_input_field('update_products[products_cost]', $currencies->format($listing['products_cost']), 'style="width: 60px"') . 'onChange=("updateProductsField('update', ' . $listing['products_id'] . 'products_cost', encodeURIComponent(this.value))")';

however obviously that doesn't work
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question