Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamicaly Linked Drop Down Lists

Status
Not open for further replies.

bam720

Technical User
Sep 29, 2005
289
US
I am working on a project where I have one List that contains the company name, and the second list is the companies location (One Company can have many locations). I want the user to pick the company and then only be able to select the relevant locations. I udnerstand that using php the form needs to submitted, but am unsure of how that works. I've tried using the "this.form.submit()" method which to my understanding is a javascript call. However this call is not doing anything at all. Here is the relevant code:
Code:
<form action="eform.php" method="post" name="client">
<p align="left"><strong>Client Information </strong></p>
<p align="left"> Name: 
<?php
	$conn = new COM('ADODB.Connection');  //for MS Access connection
	$conn = odbc_connect('clientinfo','Terminal','');

	echo'<select name="ClientName" onchange=>"this.form.submit()"';
		$sql = 'SELECT * FROM Clients';
		$clookup = odbc_exec($conn,$sql);
  		while (odbc_fetch_row($clookup))
			{
			$PID=odbc_result($clookup,"PrimeID");
			if($PID!=$PrevPID)
   				echo "<option value=\"".$PID."\">".$PID."</option><br>";
			$PrevPID=$PID;
    		}
		echo '</select>';
?>
  </p>
<p align="left">Location: 
<?php
	$conn = new COM('ADODB.Connection');  //for MS Access connection
	$conn = odbc_connect('clientinfo','Terminal','');

	echo'<select name="Location" onchange=>';
		$sql = 'SELECT * FROM Clients WHERE PrimeID = '.$_POST['ClientName'];
		$clookup = odbc_exec($conn,$sql);
  		while (odbc_fetch_row($clookup))
			{
			$Loc=odbc_result($clookup,"SecondID");
			if($PID!=$PrevPID)
   				echo "<option value=\"".$Loc."\">".$Loc."</option><br>";
			$PrevPID=$PID;
    		}
		echo '</select>';
?>
</p>
</form>

Thanks
 
Nevermind It was a simple typo error.
Code:
echo'<select name="ClientName" onchange=>"this.form.submit()"';
And having worked in ADA for so long => looks completly valid but should be
Code:
echo'<select name="ClientName" onchange="this.form.submit()">';
 
This really is a JavaScript question. But, here's an answer:
Change your code to onSubmit="document.client.submit();"
The identifier 'this' refers to the current element, which is a 'select'. You need to refer to the form itself, either using the document.forms[0].submit() [given it is the first form on the page], or get it with DOM [then the form tag needs an id], or by name as shown above.
 
DRJ478, the syntax is correct, since according to html DOM all form elements contain an attribute called form which returns form element that contains the current element (this). So, the syntax is correct and will work. More here:

However, you are right, it is a JS question rather than php one.
 
vragabond
Thanks for the point - there's always something to learn.
However, in order to be independent from DOM Level 2 requirements the suggested code should also work.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top