Help in two dropdown form

Hi…
Can anyone help me how to synchronize the two dropdown field…
Example:
I have two tables 1 for the Category other for SubCategory.

The output should be, if i have a field for Category.

CatID CatName
1 Door
2 Window

and for SubCategory

CatID SubCatName
1 Knob
1 Lock
2 Glass
2 Lock

Now how do i synchronize it in the dropdown field base on the CatID.
Thanks…

[google]linked|chained select boxes[/google]

Hi,

Can anyone help me how to populate the dropdownlist and get the id of the data.
this is my script.it works just fine if i delete the hidden text but i need the hidden text to pass the variable of the said data…Thanks…


<table>
<form action='catsubsamp.php' method='post'>
	<tr>
		<td align='right'><b>Category<font color=red>*</font>: </b></td>	
			<td>
				<?php 
					echo "<select class='user' name='user' tabindex='1'>";
					echo "<option></option>";
					while($user1=mssql_fetch_array($catname)){
						echo "<option value='$user1[CatName]'>".$user1['CatName']."</option>"; 
							echo "<input type='hidden' value='$user1[Catid]' name='catidname'>";
					}
							
					echo '</select>';

				?>
			</td>
	</tr>
	<tr>
		<td><b>Sub-Category</b></td>
		<td>
			<input type='text' name='cat'>
		</td>
	</tr>
	<tr>
		<td>
			<input type='submit' name='save' value='Save'>
		</td>
	</tr>
</form>
</table>

thanks for the linked…it is applicable if i just choose the ID of the said Category for the subcategory…i’m just confused…Thanks

It looks as if you are asking how to do a join on two tables, but as I am not 100% what you mean - show us the output of these 2 sql queries;

describe category;

describe subcategory;

<? echo "<option value=\\"" . $user1['CatId'] . "\\">" . $user1['CatName'] . "</option>"; ?>
while($user1=mssql_fetch_array($catname)){
echo "<option value='" . $user1['Catid'] . "'>" . $user1['CatName']. "</option>" . PHP_EOL ; 
}

If you are using auto-generated id numbers as Private Keys on a table, one generally passes the id of the chosen cat as the returned value of a select, as indicated above.

Off Topic:

Threads merged