I am not sure if PHP or JS is causing this issue, please tell me if I should ask in JS.
I have some code which created a dynamic drop down list and then queries a database for record data.
This works fine if i use the submit button but not if I use onchange=submit(). The submit button causes the page to refresh and load the database entry. Onchange=submit() causes the page to refresh and show the drop down list again.
Any help?
I have some code which created a dynamic drop down list and then queries a database for record data.
This works fine if i use the submit button but not if I use onchange=submit(). The submit button causes the page to refresh and load the database entry. Onchange=submit() causes the page to refresh and show the drop down list again.
Any help?
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Time and Fees Data</title>
<!--
Generates a dynamic drop down list of all
client codes in Time & Fees.
When a client is selected the page refreshes
and loads the client details from Time & Fees
-->
<style type="text/css">
<!--
body {font-family:verdana; font-size:11px; font-style:normal; font-weight:normal;}
th {color:white; background-color:gray; font-size:11px;}
td {background-color: silver; font-size:11px;}
-->
</style>
</head>
<body>
<?php
// odbc_query.php
$odbc_dsn = "timeandfees_db";
$odbc_userid = "";
$odbc_password = "";
if(@$_POST["custname"]!="") {
//if (!isset($_POST['TFsubmit'])) { // Step 1: fill initial form and present it
$tmp = array();
$tmp[] = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
$tmp[] = '<select name="custname" onchange="this.form.submit();">';
$tmp[] = '<option value="">Select from list...</option>';
$query = "SELECT Clients.ClientKey FROM clients ORDER BY Clients.ClientKey";
if(!($odbc_db = odbc_connect($odbc_dsn, $odbc_userid, $odbc_password)))
die ("Could not connect ot ODBC data source $odbc_dsn");
if(!($odbc_rs = odbc_do($odbc_db, $query)))
die("Error executing query $query");
$num_cols = odbc_num_fields($odbc_rs);
if($num_cols < 1) die("Query returned an empty set");
while(odbc_fetch_row($odbc_rs)) $tmp[] = '<option>' . odbc_result($odbc_rs,'ClientKey') . '</option>';
$tmp[] = '</select>';
$tmp[] = '<input type="submit" name="TFsubmit" value="Display Time and Fees Information">';
$tmp[] = '</form>';
echo implode("\n",$tmp)."\n";
echo "<input type=\"text\" name=\"searchterm\" size=\"25\">";
}
else { // Step 2: Display data
$tmp = array();
// $valid_cust = validate($_POST['custname']); //make sure that input is in the format you are expecting
$valid_cust = $_POST['custname'];
$query = "SELECT Clients.ClientKey, Clients.CoyName, Addresses.* FROM Addresses INNER JOIN Clients ON
Addresses.AddrKey = Clients.AddrKey where Clients.ClientKey = '" . $valid_cust . "'";
if(!($odbc_db = odbc_connect($odbc_dsn, $odbc_userid, $odbc_password)))
die ("Could not connect ot ODBC data source $odbc_dsn");
if(!($odbc_rs = odbc_do($odbc_db, $query)))
die("Error executing query $query");
$num_cols = odbc_num_fields($odbc_rs);
if($num_cols < 1) die("Query returned an empty set");
?>
<table summary="" style="{width:100%;}">
<tr>
<?php
for($a=1;$a<=$num_cols;$a++)
{
?>
<th style="{text-align:left;}">
<b>
<?php
echo odbc_field_name($odbc_rs, $a);
?>
</b>
</th>
<?php
}
?>
</tr>
<?php
while(odbc_fetch_row($odbc_rs))
{
?>
<tr>
<?php
for($a=1;$a<=$num_cols;$a++)
{
$data = odbc_result($odbc_rs, $a);
echo "<td>$data</td>";
}
?>
</tr>
<?php
}
}
?>
</table>
</body>
</html>