i m working on select boxes. there are two select boxes one is to select country and other is to select state. when the user selects on country for.ex.US then all the states in US should appear in the second select box(state select box)
Plz help me
<?
require_once("..\includes\util.php");
class Type extends MySQL_class
{
var $Cat, $CatId, $SubCat, $SubCatId;
function __construct()
{
$this->Create("ticket");
}
function getCountry()
{
$query="SELECT * FROM `country_master`";
$this->Query($query);
for($i=0; $i< $this->rows; $i++)
{
$this->Fetch($i);
$this->Country[$i]= $this->data["country_name"];
$this->CountryId[$i]= $this->data["country_id"];
}
}
function getState($selcountry)
{
$query = "SELECT * FROM `state_master` WHERE `country_id` = '$selcountry'";
$this->Query($query);
for($i=0; $i < $this->rows; $i++)
{
$this->Fetch($i);
$this->State[$i] = $this->data["state_name"];
$this->StateId[$i] = $this->data["state_id"];
}
}
}
$t= new Type();
$t->getCountry();
?>
<html>
<head>
<title>Add Subcategory</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../stylesheet1.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td height="58" colspan="3"> </td>
</tr>
<tr>
<td width="16%" height="424"> </td>
<td width="61%" valign="top"><table width="70%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#8F8F8F">
<tr>
<td><form name="form1" method="post" action="addState_insert.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="20" class="thadmin" bgcolor="#EAEAEA"> </td>
<td height="20" class="thadmin" colspan="4">New
State</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td width="4%"> </td>
<td width="30%" class="tdadmin">Select Country:</td>
<td width="23%"><select name="selcountry" class="text1">
<option value="">--</option>
<?php
foreach($t->Country as $i=> $value)
{ ?>
<option value=<?= $t->CountryId[$i]?> class="text1"><?=$value?></option>;
<? }?>
</select></td>
</tr>
<? $t->getState($selcountry);?>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td width="4%"> </td>
<td width="30%" class="tdadmin">Select State:</td>
<td colspan="3" class="tdadmin"><select name="selstate" class="text1">
<option value="">--</option>
<?php
foreach($t->State as $i=> $value)
{ ?>
<option value=<?= $t->StateId[$i]?> class="text1"><?=$value?></option>;
<? }?>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td width="4%"> </td>
<td colspan="4" align="center"><input type="submit" class="button" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
The values in select box is from the database
MySQL_class is written to insert, update, delete purpose