Jump to content

Dynamic drop down box


nealios

Recommended Posts

I have a dynamic drop down box that populates with customer names from my database.

 

This works correctly and communicates with the database and i can update my job table once a customer has been chosen/allocated to each job.

 

However when i come out and go back into the form although the customer information is still in the database the drop down obviously defaults back to the first customer in the database.

 

Is there a way in which the drop down box can default to the value that was previously selected which is stored in the database?

 

   $row = mysql_fetch_array($result);
    $sql = "SELECT `cid`, `first_name`, `surname` FROM `customer`
            ORDER BY `surname`
            ASC
           ";
    if ( !$result = mysql_query($sql) ) {
        abort_script('Database error: ' . mysql_error(), '');
    } else {
        $customer_select = "            <select name=\"cid\" >\n";
        while( $data = mysql_fetch_array($result) ) {
             $customer_select .= "                <option value=\"{$data['cid']}\">{$data['first_name']} {$data['surname']}</option>\n";
        }
        $customer_select .= "            </select>\n";

 

 

Many thanks

Link to comment
Share on other sites

I am assuming that after you pick your customer you have to hit some type of post button correct?

 

If so, you can modify the database so that it contains a "last picked" slot that is a 1 or a 0, when the form is submitted, it would search the database for a 1, or the last one last picked, and change it to a 0 and then change the current customer from a 0 to a 1.

 

Then in the customer selection include an if statement that checks for the 1 and then adds the value ""selected" to the html which should make it automatically selected.

 

So i guess it is kind of a long work around, but it should work.

 

~D

Link to comment
Share on other sites

I had the same sort of requirement.  I wanted to make an sql request and populate a dropdown with categories from a db table and then when the user clicks through to a preview page the dropdown remembers the choice from the first (submit) page.

try something like this:

 

function SelectName($name) {
    $selname = mysql_query("SELECT `cid`, `first_name`, `surname` FROM `customer`
            ORDER BY `surname`
            ASC");
    $a = 1;
    echo "<select name=\"name\">";
    if ($name == 0) {
$sel = "selected";
    } else {
$sel = "";
    }
    echo "<option value=\"0\" $sel>Customer Name</option>";
    while(list($cid, $firstname, $surname) = mysql_fetch_row($selname)) {
if ($c_id == $name) {
    $sel = "selected";
} else {
    $sel = "";
}
echo "<option value=\"$cid\" $sel>'.$firstname.' '.$surname.'</option><br>";
$a++;
    }
echo "</select>";

}

Link to comment
Share on other sites

You could set up a session variable that does the trick also.

The only thing is that you have to remember to put start_session() at the top of the pages.

 

pretty much rather then having it written to an SQL database, it would be stored locally to a session vairble, which makes a lot more sense.

Link to comment
Share on other sites

Thanks for your replies.

 

Ive adapted the code so it now works with my db so I Can still update correctly.

 

However rather than the drop down defaulting to the name stored in the database corrosponding to the customer ID. It now defaults to the last person in the list (ordered by surname) any idea where its going wrong?

 

$selname = mysql_query("SELECT `cid`, `first_name`, `surname` FROM `customer`
            ORDER BY `surname`
            ASC");
    $a = 1;
    $customer_select .= "<select name=\"cid\" onchange=\"showCustomer(this.value)\">";
    if ($name == 0) {
$sel = "selected";
    } else {
$sel = "";
    }
    $customer_select .= "<option value=\"0\" $sel>Customer Name</option>";
    while(list($c_id, $firstname, $surname) = mysql_fetch_row($selname)) {
if ($cid == $name) {
    $sel = "selected";
} else {
    $sel = "";
}
$customer_select .= "<option value=\"$cid\" $sel>$firstname $surname</option><br>";
$a++;
    }
$customer_select .= "</select>";

 

Thanks

Link to comment
Share on other sites

if ( $numrows === 1 ) {
    send_header();
    $row = mysql_fetch_array($result);
$selname = mysql_query("SELECT `cid`, `first_name`, `surname` FROM `customer`
            ORDER BY `surname`
            ASC");
    $a = 1;
    $customer_select .= "<select name=\"cid\" onchange=\"showCustomer(this.value)\">";
    if ($name == 0) {
$sel = "selected";
    } else {
$sel = "";
    }
    $customer_select .= "<option value=\"0\" $sel>Customer Name</option>";
    while(list($c_id, $firstname, $surname) = mysql_fetch_row($selname)) {
if ($cid == $name) {
    $sel = "selected";
} else {
    $sel = "";
}
$customer_select .= "<option value=\"$cid\" $sel>$firstname $surname</option><br>";
$a++;
    }
$customer_select .= "</select>";

}

    // $row contains our Job record, and now $customer_select has our drop-down with cid's as values. We can now echo the HTML.
    echo"
<p>
<form name=\"record_mod\" method=\"post\" action=\"jobadmin.php\">
<table border=\"1\" align =\"center\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td>
      
  			<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"4\">
        			<tr>
          				<td width=\"90\"><b>JobID: {$row['JobID']}</td>
        			</tr>
			<table>


			<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"4\">
        			<tr>
          				<td width=\"75\" align=\"right\"><b>Start Date:
	  				<input id=\"demo3\" width=\"75\" align=\"right\" type=\"text\" name=\"StartDate\" value=\"{$row['StartDate']}\">
          	  				<a href=\"javascript:NewCal('demo3','ddmmyyyy')\"><img src=\"cal.gif\" width=\"16\" 			height=\"16\" border=\"0\"></a>
					</td>

          				<td width=\"75\" align=\"left\"><b>End Date:
            				<input id=\"demo4\" type=\"text\" name=\"EndDate\" value=\"{$row['EndDate']}\">
            				<a  href=\"javascript:NewCal('demo4','ddmmyyyy')\"><img  src=\"cal.gif\" width=\"16\"  height=\"16\" border=\"0\"></a>
					</td>
        			</tr>

			</table>

	  <p>
	  		<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"4\">
        			<tr>
          				<td align=\"left\"><b>Job Address</td>
        			</tr>
      			</table>

			<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"4\">
				<tr>
          				<td width=\"75\" align=\"right\"><b>Address 1:</td>
          				<td><input name=\"JobAddress1\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress1']}\" /></td>
          			</tr>
				<tr>	
					<td width=\"75\" align=\"right\"><b>Address 2:</td>
          				<td><input name=\"JobAddress2\" type=\"text\" size=\"30\" maxlength=\"20\" value=\"{$row['JobAddress2']}\" /></td>
				</tr>
			</table>


			 <table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
        			<tr>
          				<td width=\"75\" align=\"right\"><b>Town:</td>
          				<td><input name=\"JobTown\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['JobTown']}\" /></td>
          				<td><b>County:</td>
          				<td><input name=\"JobCounty\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['JobCounty']}\" /></td>
          				<td><b>Postcode:</td>
          				<td><input name=\"JobPostcode\" type=\"text\" size=\"15\" maxlength=\"8\" value=\"{$row['JobPostcode']}\" /></td>

      			</table>
<p>
  
  
    		<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
			 <hr align=\"left\" width=\"650\">
        			<tr>
          				<td align=\"left\"><b>Job Details</td>
        			</tr>
      			</table>
  
  			<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"4\">
       				<tr>
          				<td width=\"75\" align=\"right\"><b>Price :</td>
          				<td><input name=\"Price\" type=\"text\" size=\"15\" maxlength=\"25\" value=\"{$row['Price']}\" /></td>
				</tr>
				<tr>	
					<td align=\"right\"><b>Labour Type:</td>
					<td><input name=\"Type\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Type']}\" /> Select:$labour_select</td>
        			</tr>


        			<tr>
           				<td width=\"75\" align=\"right\"><b>Description:</td>	 


					<td><textarea name=\"Description\" rows=\"10\" cols=\"65\">" . stripslashes($row['Description']) . "</textarea>
					</td>
	 			</tr>

	 			<tr>
	  				<td width=\"75\" align=\"right\"><b>Materials:</td>
          				<td><input name=\"Materials\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Materials']}\" /></td>
	   			</tr>
	   
			</table>

			<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"4\">
				<tr>
					<td width=\"75\" align=\"right\"><b>Invoice Date:</td>
            				<td><input id=\"demo5\" type=\"text\" name=\"InvoiceDate\" value=\"{$row['InvoiceDate']}\">
            				<a  href=\"javascript:NewCal('demo5','ddmmyyyy')\"><img  src=\"cal.gif\" width=\"16\"  height=\"16\" border=\"0\"></a>
					</td>
				</tr>
				<tr>
					<td width=\"75\" align=\"right\"><b>Paid:</td>
					<td><input name=\"Decision\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['Decision']}\" />
					Select:$paid_select</td>
				</tr>	
			</table>



<p>	
	  		<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
        		<hr align=\"left\" width=\"650\">
				<tr>
          				<td align=\"left\"><b>Customer Details</td>
        			</tr>
      			</table>

			<table>
				<tr>
          				<td width=\"75\" align=\"right\"><b>First Name:</td> 
          				<td><input name=\"first_name\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['first_name']}\" /></td>
				</tr>
					<td width=\"75\" align=\"right\"><b>Surname:</td> 
          				<td><input name=\"surname\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['surname']}\" /></td>
          				<td><b>Select Customer: $customer_select</td>

			</table>


			<table border \"0\">	  	  
				<tr> 
					<td><div id=\"txtHint\"><b>Customer info will be listed here.</b></div></td> </tr>
				</tr>
	 		</table>
  		
<p>
  		  		
			<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
        			<hr align=\"left\" width=\"650\">
				<tr>
          				<td align=\"left\"><b>Engineer Details</td>
        			</tr>
      			</table>
  		

			<table>
				<tr>
  						<td width=\"75\" align=\"right\"><b>Engineer First Name:</td> 
        				<td><input name=\"EngFirstName\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['EngFirstName']}\" /></td>
				</tr>
				<tr>
					<td width=\"75\" align=\"right\"><b>Engineer Surname:</td> 
        				<td><input name=\"EngSurname\" type=\"text\" size=\"20\" maxlength=\"25\" value=\"{$row['EngSurname']}\" /></td>  
	 				<td><b>Select Engineer: $engineer_select</td> 
				</tr>
			</table>  
<p>
	  

     			<table border=\"0\" width=\"750\" cellspacing=\"0\" cellpadding=\"0\">
        			<hr align=\"left\" width=\"650\">
				<tr>
          				<td align=\"left\"><b>Process</td>
        			</tr>
      			</table>
     
 			 <table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
        			<tr>
          				<td><input name=\"process\" type=\"radio\" value=\"1\" /> <b>Update Record</td>
          				<td><input name=\"process\" type=\"radio\" value=\"2\" /> <b>New Record</td>
          				<td><input name=\"process\" type=\"radio\" value=\"3\" /> <b>Delete Record</td>
        			</tr>
      			</table>


     	 		<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
        			<tr>
          				<td colspan=\"3\"><a href=\"#\" onclick=\"record_mod.submit()\" class=\"button\"><span class=\"icon\"> Submit </span><a></td>
        	  			<td><a href=\"jobs.php\" class=\"button\" span class=\"icon\"> Records List </span></a></td>      
          				<td><a href=\"jobadmin.php?JobID=0&process=4\" class=\"button\" span class=\"icon\"> Synchronize</span></a></td>
          			<td style=\"padding-left: 50px;\"></td>
          			<td><a href=\"jobadmin.php?JobID=$JobID&process=5&move=2\" class=\"button\" span class=\"icon\">Previous</span></a></td><td><b>Navigate</td>
          			<td><a href=\"jobadmin.php?JobID=$JobID&process=5&move=1\" class=\"button\" span class=\"icon\">Next</span></a></td>
          			<td><a href=\"invoice.php?JobID={$row['JobID']}\" TARGET=\"_blank\" class=\"button\" span class=\"icon\"> Create Invoice </span></a></td> 
	  

        </tr>
      </table>
    </td>
  </tr>
</table></p>
<input name=\"JobID\" type=\"hidden\" value=\"$JobID\" />
</form>";

 

 

Many thanks

Link to comment
Share on other sites

Sorry, it appears I did not make myself clear.

 

Could you please post the HTML output for this script, meaning once you run the script in a browser view the source and paste over the section relating to the drop down box. (right click in the browser -> view source)

 

I have a feeling it is labeling them all as selected which would be verified by viewing the source of the output page.

 

~D

Link to comment
Share on other sites

I think this is what you want!

 

 

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<script language="javascript"  type="text/javascript"  src="datetimepicker.js">
</script>

<script src="selectcustomer.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Individual Record Editor</title>



<style type="text/css" media="screen">
#printhead {display:none;}
html {
height:100%; 
max-height:100%; 
padding:0; 
margin:0; 
border:0; 
background:#FFFFFF; 
font-size:85%; 
font-family: "trebuchet ms", tahoma, verdana, arial, sans-serif;
/* hide overflow:hidden from IE5/Mac */ 
/* \*/ 
overflow: hidden; 
/* */ 
}

body {height:100%; max-height:100%; overflow:hidden; padding:0; margin:0; border:0;}
#content {display:block; height:100%; max-height:100%; overflow:auto; padding-left:; position:relative; z-index:3; word-wrap:break-word;}
#head {position:absolute; margin:0; top:0; right:0px; display:block; width:100%; height:100px; background:#fff; font-size:4em; z-index:5; color:#000; border-bottom:0 solid #000;}
#foot {position:absolute; margin:0; bottom:-1px; right:18px; display:block; width:100%; height:51px; background:#fff; color:#000; text-align:right; font-size:2em; z-index:4; border-top:1px solid #000;}
.pad1 {display:block; width:18px; height:50px; float:left;}
.pad2 {display:block; height:100px;}
#content p {padding:5px;}
.bold {font-size:1.2em; font-weight:bold;}
.red {color:#c00; margin-left:5px; font-family:"trebuchet ms", "trebuchet", "verdana", sans-serif;}
h2 {margin-left:5px;}
h3 {margin-left:5px;}
</style>

<style type="text/css" media="print">
html {padding:0; margin:0; border:0; background:#fff; font-size:10pt; font-family: arial, sans-serif;}
body {padding:0; margin:0; border:0;}
#content {display:block; position:relative; z-index:3; word-wrap:break-word;}
#head {display:none;}
#printhead {height:100px; background:#fff; font-size:24pt; color:#000; border-bottom:1px solid #000;}
#printfoot {height:50px; background:#fff; color:#000; text-align:right; font-size:12pt; border-top:1px solid #000; margin-top:20px;}
#foot {display:none;}
</style>











<style type="text/css">
.preload2 {background: url(prodrop2/button4.gif);}
.menu2 {padding:0 0 0 32px; margin:0; list-style:none; height:40px; background:#fff url(prodrop2/button1a.gif) repeat-x; position:relative; font-family:arial, verdana, sans-serif; }
.menu2 li.top {display:block; float:left; position:relative;}
.menu2 li a.top_link {display:block; float:left; height:40px; line-height:33px; color:#bbb; text-decoration:none; font-size:11px; font-weight:bold; padding:0 0 0 12px; cursor:pointer;}
.menu2 li a.top_link span {float:left; display:block; padding:0 24px 0 12px; height:40px;}
.menu2 li a.top_link span.down {float:left; display:block; padding:0 24px 0 12px; height:40px; background:url(prodrop2/down.gif) no-repeat right top;}
.menu2 li a.top_link:hover {color:#fff; background: url(prodrop2/button4.gif) no-repeat;}
.menu2 li a.top_link:hover span {background:url(prodrop2/button4.gif) no-repeat right top;}
.menu2 li a.top_link:hover span.down {background:url(prodrop2/button4a.gif) no-repeat right top;}

.menu2 li:hover > a.top_link {color:#fff; background: url(prodrop2/button4.gif) no-repeat;}
.menu2 li:hover > a.top_link span {background:url(prodrop2/button4.gif) no-repeat right top;}
.menu2 li:hover > a.top_link span.down {background:url(prodrop2/button4a.gif) no-repeat right top;}


.menu2 table {border-collapse:collapse; width:0; height:0; position:absolute; top:0; left:0;}

/* Default link styling */

/* Style the list OR link hover. Depends on which browser is used */

.menu2 a:hover {visibility:visible;}
.menu2 li:hover {position:relative; z-index:200;}

/* keep the 'next' level invisible by placing it off screen. */
.menu2 ul, 
.menu2 :hover ul ul, 
.menu2 :hover ul :hover ul ul,
.menu2 :hover ul :hover ul :hover ul ul,
.menu2 :hover ul :hover ul :hover ul :hover ul ul {position:absolute; left:-9999px; top:-9999px; width:0; height:0; margin:0; padding:0; list-style:none;}

.menu2 :hover ul.sub {left:2px; top:40px; background: #fff; padding:3px 0; border:1px solid #4ab; white-space:nowrap; width:93px; height:auto;}
.menu2 :hover ul.sub li {display:block; height:20px; position:relative; float:left; width:90px;}
.menu2 :hover ul.sub li a {display:block; font-size:11px; height:20px; width:87px; line-height:20px; text-indent:5px; color:#000; text-decoration:none; border:3px solid #fff; border-width:0 0 0 3px;}
.menu2 :hover ul.sub li a.fly {background:#fff url(prodrop2/arrow.gif) 80px 7px no-repeat;}
.menu2 :hover ul.sub li a:hover {background:#4ab; color:#fff;}
.menu2 :hover ul.sub li a.fly:hover {background:#4ab url(prodrop2/arrow_over.gif) 80px 7px no-repeat; color:#fff;}
.menu2 :hover ul li:hover > a.fly {background:#4ab url(prodrop2/arrow_over.gif) 80px 7px no-repeat; color:#fff;} 

.menu2 :hover ul :hover ul,
.menu2 :hover ul :hover ul :hover ul,
.menu2 :hover ul :hover ul :hover ul :hover ul,
.menu2 :hover ul :hover ul :hover ul :hover ul :hover ul
{left:90px; top:-4px; background: #fff; padding:3px 0; border:1px solid #4ab; white-space:nowrap; width:93px; z-index:200; height:auto;}
</style>



<style type="text/css">

a.button, a.buttonDis {
display: block;
background-color: transparent;
background-image: url(buttonBackground.gif);
background-repeat: no-repeat;
width: 132px;
height: 28px;
margin: 5px auto;
padding: 5px 0 0 0;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
font-weight: bold;
text-decoration: none;
}
a.button:link, a.button:visited {
color: #002577;
}
a.button:hover, a.button:active {
background-position: 0 -36px;
color: #FF7200;
}
a.buttonDis:link, a.buttonDis:visited, a.buttonDis:hover, a.buttonDis:active {
background-position: 0 -72px;
color: #5F5F5F;
cursor: default;
}
.icon {
display: inline-block;
background-repeat: no-repeat;
padding: 0 0 5px 18px;
}
a.button:hover .icon, a.button:active .icon {
background-position: 0 -28px;
}
a.buttonDis:link .icon, a.buttonDis:visited .icon, a.buttonDis:hover .icon, a.buttonDis:active .icon {
background-position: 0 -56px;
}
/* list of button icons */
#buttonOK .icon {
background-image: url(ok.gif);
}
#buttonCancel .icon {
background-image: url(cancel.gif);
}
#buttonImport .icon {
background-image: url(import.gif);
}
</style>

</head>

<body>
<div id="printhead"></div>
<div id="head">
<div class="pad1"></div>
Ocklynge Plumbing & Heating 
<span class="preload2"></span>

<ul class="menu2">

<li class="top"><a href="http://localhost:8888/home.php" id="home" class="top_link"><span>Home</span></a></li>

<li class="top"><a href="http://localhost:8888/file.php" id="file" class="top_link"><span class="down">File</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
	<!--[if lte IE 6]><table><tr><td><![endif]-->
	<ul class="sub">

				<li><A HREF="javascript:window.print()">Print</a></li>
				<li><a href="../ie/">Export Data</a></li>

				<li><a href="../opacity/">Exit</a></li>

				<!--[if lte IE 6]></td></tr></table></a><![endif]-->
		<!--[if gte IE 7]><!--></a><!--<![endif]-->
				<!--[if lte IE 6]><table><tr><td><![endif]-->

				<!--[if gte IE 7]><!--></a><!--<![endif]-->
						<!--[if lte IE 6]><table><tr><td><![endif]-->

						<!--[if lte IE 6]></td></tr></table></a><![endif]-->
				<!--[if gte IE 7]><!--></a><!--<![endif]-->

						<!--[if lte IE 6]><table><tr><td><![endif]-->

						<!--[if lte IE 6]></td></tr></table></a><![endif]-->


				<!--[if lte IE 6]></td></tr></table></a><![endif]-->
		</li>


	</ul>
	<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li class="top"><a href="http://localhost:8888/customers.php" id="customers" class="top_link"><span class="down">Customers</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

	<!--[if lte IE 6]><table><tr><td><![endif]-->
	<ul class="sub">
		<li><a href="http://localhost:8888/customers.php">View Customers</a></li>
		<li><a href="http://localhost:8888/customersearch.php">Customer Search</a></li>
	</ul>
	<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li class="top"><a href="http://localhost:8888/jobs.php" id="jobs" class="top_link"><span class="down">Jobs</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

	<!--[if lte IE 6]><table><tr><td><![endif]-->

	<ul class="sub">
		<li><a href="http://localhost:8888/jobs.php">View Jobs</a></li>
		<li><a href="../boxes/" class="fly">Past Jobs<!--[if gte IE 7]><!--></a><!--<![endif]-->
			<!--[if lte IE 6]><table><tr><td><![endif]-->
			<ul>
				<li><a href="../mozilla/">Paid</a></li>

				<li><a href="../ie/">Unpaid</a></li>
<!--[if IE 7]><!--></a><!--<![endif]-->
					<!--[if lte IE 6]><table><tr><td><![endif]-->
					<!--[if gte IE 7]><!--></a><!--<![endif]-->
							<!--[if lte IE 6]><table><tr><td><![endif]-->
							<!--[if gte IE 7]><!--></a><!--<![endif]-->
									<!--[if lte IE 6]><table><tr><td><![endif]-->

									<!--[if lte IE 6]></td></tr></table></a><![endif]-->

							<!--[if lte IE 6]></td></tr></table></a><![endif]-->



					<!--[if lte IE 6]></td></tr></table></a><![endif]-->

			<!--[if lte IE 6]></td></tr></table></a><![endif]-->
			</ul>		
		</li>

		<li><a href="../mozilla/">Job Search</a></li>
	</ul>
	<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li class="top"><a href="http://localhost:8888/suppliers.php" id="suppliers" class="top_link"><span class="down">Suppliers</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

	<!--[if lte IE 6]><table><tr><td><![endif]-->
	<ul class="sub">
		<li><a href="../ie/">View All</a></li>
		<li><a href="../opacity/">Supplier Search</a></li>
	</ul>
	<!--[if lte IE 6]></td></tr></table></a><![endif]-->

</li>



<li class="top"><a href="http://localhost:8888/engineers.php" id="engineers" class="top_link"><span class="down">Engineers</span><!--[if gte IE 7]><!--></a><!--<![endif]-->

	<!--[if lte IE 6]><table><tr><td><![endif]-->
	<ul class="sub">
		<li><a href="../ie/">View All</a></li>
		<li><a href="../opacity/">Engineer Search</a></li>
	</ul>
	<!--[if lte IE 6]></td></tr></table></a><![endif]-->

</li>
<li class="top"><a href="http://localhost:8888/help.php" id="help" class="top_link"><span>Help</span></a></li>
</ul>
</div>


<div id="content">


<div class="pad2"></div>





<p>
<form name="record_mod" method="post" action="jobadmin.php">
<table border="1" align ="center" width="750" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      
  			<table border="0" width="750" cellspacing="0" cellpadding="4">
        			<tr>
          				<td width="90"><b>JobID: 1</td>

        			</tr>
			<table>


			<table border="0" width="750" cellspacing="0" cellpadding="4">
        			<tr>
          				<td width="75" align="right"><b>Start Date:
	  				<input id="demo3" width="75" align="right" type="text" name="StartDate" value="1-11-2007">
          	  				<a href="javascript:NewCal('demo3','ddmmyyyy')"><img src="cal.gif" width="16" 			height="16" border="0"></a>
					</td>

          				<td width="75" align="left"><b>End Date:
            				<input id="demo4" type="text" name="EndDate" value="6-11-2007">

            				<a  href="javascript:NewCal('demo4','ddmmyyyy')"><img  src="cal.gif" width="16"  height="16" border="0"></a>
					</td>
        			</tr>

			</table>

	  <p>
	  		<table border="0" width="750" cellspacing="0" cellpadding="4">
        			<tr>
          				<td align="left"><b>Job Address</td>

        			</tr>
      			</table>

			<table border="0" width="750" cellspacing="0" cellpadding="4">
				<tr>
          				<td width="75" align="right"><b>Address 1:</td>
          				<td><input name="JobAddress1" type="text" size="30" maxlength="20" value="42 The Road" /></td>
          			</tr>
				<tr>	
					<td width="75" align="right"><b>Address 2:</td>

          				<td><input name="JobAddress2" type="text" size="30" maxlength="20" value="Samson Hill" /></td>
				</tr>
			</table>


			 <table border="0" cellspacing="0" cellpadding="4">
        			<tr>
          				<td width="75" align="right"><b>Town:</td>
          				<td><input name="JobTown" type="text" size="20" maxlength="25" value="Shoram" /></td>
          				<td><b>County:</td>

          				<td><input name="JobCounty" type="text" size="20" maxlength="25" value="West Sussex" /></td>
          				<td><b>Postcode:</td>
          				<td><input name="JobPostcode" type="text" size="15" maxlength="8" value="BN21 2PN" /></td>

      			</table>
<p>
  
  
    		<table border="0" width="750" cellspacing="0" cellpadding="0">
			 <hr align="left" width="650">
        			<tr>
          				<td align="left"><b>Job Details</td>

        			</tr>
      			</table>
  
  			<table border="0" width="750" cellspacing="0" cellpadding="4">
       				<tr>
          				<td width="75" align="right"><b>Price :</td>
          				<td><input name="Price" type="text" size="15" maxlength="25" value="700.00" /></td>
				</tr>
				<tr>	
					<td align="right"><b>Labour Type:</td>

					<td><input name="Type" type="text" size="20" maxlength="25" value="another" /> Select:            <select name="LabourID">
                <option value="2">another</option>
                <option value="1">Onekind</option>
            </select>
</td>
        			</tr>


        			<tr>

           				<td width="75" align="right"><b>Description:</td>	 


					<td><textarea name="Description" rows="10" cols="65">Bathroomdmsamd sadsa;ldm dnmksajdkas djshadjk jhdksa hdkjsah dhkasn djhdb xsadbjsabd aasdbjas djasd sjdbsabhdjs   asjdbsja dajsdbjas djsa djas dj asjdbj sadbsamd sjabdksajbdjsa</textarea>
					</td>
	 			</tr>

	 			<tr>
	  				<td width="75" align="right"><b>Materials:</td>
          				<td><input name="Materials" type="text" size="20" maxlength="25" value="450.00" /></td>
	   			</tr>

	   
			</table>

			<table border="0" width="750" cellspacing="0" cellpadding="4">
				<tr>
					<td width="75" align="right"><b>Invoice Date:</td>
            				<td><input id="demo5" type="text" name="InvoiceDate" value="26/12/2007">
            				<a  href="javascript:NewCal('demo5','ddmmyyyy')"><img  src="cal.gif" width="16"  height="16" border="0"></a>
					</td>
				</tr>

				<tr>
					<td width="75" align="right"><b>Paid:</td>
					<td><input name="Decision" type="text" size="20" maxlength="25" value="No" />
					Select:            <select name="PaidID">
                <option value="1">No</option>
                <option value="2">Yes</option>
            </select>

</td>
				</tr>	
			</table>



<p>	
	  		<table border="0" width="750" cellspacing="0" cellpadding="0">
        		<hr align="left" width="650">
				<tr>
          				<td align="left"><b>Customer Details</td>
        			</tr>

      			</table>

			<table>
				<tr>
          				<td width="75" align="right"><b>First Name:</td> 
          				<td><input name="first_name" type="text" size="20" maxlength="25" value="Tony" /></td>
				</tr>
					<td width="75" align="right"><b>Surname:</td> 
          				<td><input name="surname" type="text" size="20" maxlength="25" value="Wong" /></td>
          				<td><b>Select Customer: <select name="cid" onchange="showCustomer(this.value)"><option value="0" selected>Customer Name</option><option value="" selected>Adam Black</option><br><option value="" selected>Harriet Coombs</option><br><option value="" selected>Tom Neal</option><br><option value="" selected>Peter Pan</option><br><option value="" selected>Tony Wong</option><br></select></td>


			</table>


			<table border "0">	  	  
				<tr> 
					<td><div id="txtHint"><b>Customer info will be listed here.</b></div></td> </tr>
				</tr>
	 		</table>
  		
<p>
  		  		
			<table border="0" width="750" cellspacing="0" cellpadding="0">
        			<hr align="left" width="650">

				<tr>
          				<td align="left"><b>Engineer Details</td>
        			</tr>
      			</table>
  		

			<table>
				<tr>
  						<td width="75" align="right"><b>Engineer First Name:</td> 
        				<td><input name="EngFirstName" type="text" size="20" maxlength="25" value="Anne-Marie" /></td>

				</tr>
				<tr>
					<td width="75" align="right"><b>Engineer Surname:</td> 
        				<td><input name="EngSurname" type="text" size="20" maxlength="25" value="Neal" /></td>  
	 				<td><b>Select Engineer:             <select name="EngineerID">
                <option value="1">Unassigned Engineer</option>
                <option value="2">Justin  Neal</option>
                <option value="3">Anne-Marie Neal</option>

                <option value="5">Laurie Neal</option>
                <option value="6">Anne-Marie Neal</option>
            </select>
</td> 
				</tr>
			</table>  
<p>
	  

     			<table border="0" width="750" cellspacing="0" cellpadding="0">
        			<hr align="left" width="650">

				<tr>
          				<td align="left"><b>Process</td>
        			</tr>
      			</table>
     
 			 <table border="0" cellspacing="2" cellpadding="4">
        			<tr>
          				<td><input name="process" type="radio" value="1" /> <b>Update Record</td>
          				<td><input name="process" type="radio" value="2" /> <b>New Record</td>

          				<td><input name="process" type="radio" value="3" /> <b>Delete Record</td>
        			</tr>
      			</table>


     	 		<table border="0" cellspacing="2" cellpadding="4">
        			<tr>
          				<td colspan="3"><a href="#" onclick="record_mod.submit()" class="button"><span class="icon"> Submit </span><a></td>
        	  			<td><a href="jobs.php" class="button" span class="icon"> Records List </span></a></td>      
          				<td><a href="jobadmin.php?JobID=0&process=4" class="button" span class="icon"> Synchronize</span></a></td>

          			<td style="padding-left: 50px;"></td>
          			<td><a href="jobadmin.php?JobID=1&process=5&move=2" class="button" span class="icon">Previous</span></a></td><td><b>Navigate</td>
          			<td><a href="jobadmin.php?JobID=1&process=5&move=1" class="button" span class="icon">Next</span></a></td>
          			<td><a href="invoice.php?JobID=1" TARGET="_blank" class="button" span class="icon"> Create Invoice </span></a></td> 
	  

        </tr>
      </table>
    </td>

  </tr>
</table></p>
<input name="JobID" type="hidden" value="1" />
</form>

<div class="pad2"></div>

</div>
<div id="foot">Footer</div>
<div id="printfoot">Copyright ©2004/5/6 tom neal</div>
</body>
</html>

Link to comment
Share on other sites

Oh k, here are the 2 conclusions I came to:

 

1. You have a misspelling in one of your variable names

<?php
while(list($c_id, $firstname, $surname) = mysql_fetch_row($selname)) {
if ($cid == $name)
?>

One time it is $c_id the next time it is $cid

 

2. Since you have the $name as being unset (no customer selected yet) and $cid unset (the misspelling problem) it sees $cid as being equal to $name, so it is putting the Selected at the end of all the options

<select name="cid" onchange="showCustomer(this.value)">
     <option value="0" selected>Customer Name</option>
     <option value="" selected>Adam Black</option><br>
     <option value="" selected>Harriet Coombs</option><br>
     <option value="" selected>Tom Neal</option><br>
     <option value="" selected>Peter Pan</option><br>
     <option value="" selected>Tony Wong</option><br>
     </select>

(formated to be pretty)

You can also see that the Value is not being set, which is directly related to the misspelling of $cid

 

So the conclusion is, Change $c_id into $cid and your life will be a lot better.

 

~D

 

ps. if you ever post large chunks of code again, include the <?php and ?> in the beginning and end, it makes it color coded and stuff like this sticks out right away.

Link to comment
Share on other sites

Thanks for your reply!

 

sounds stupid but I did notice that the $cid was mispelt as it was from the example posted by another person.

When the $cid was mispelt it defaulted to the last record in the customer table (sorted by surname).

 

I have tested it spelt correctly but the dropdown defaults to the title Customer Name rather than the customer name that is currently stored in the database.

 

For example in my database if the field was set to Peter Pan next time i go into the form the drop down will default to Peter Pan.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.