Hi People, got a small issue.
I have 3 select boxes, I mean dropdown list
country dropdown list... then a state and then a town...
I'm fetching data from database and loading it in the first dropdown list (country)
On change of country, states get loaded and on change of states, town gets loaded.
All is working fine...
But when I submit this data... I echoed country and its getting displayed in the backend page... but state and town values get vanished.... I want these selected values to get posted in the backend php page.
This is my code:
<?php include('config.php');
$sqlcountry= "SELECT DISTINCT country FROM contact";
$resultcountry= mysql_query($sqlcountry);
?>
<html>
<script src="js/jquery.min.js"></script>
<script type="text/javascript">
function get_states(country)
{
$.ajax({
type: "POST",
url: "states.php", /* The country id will be sent to this file */
beforeSend: function () {
$("#state").html("<option>Loading ...</option>");
},
data: "country="+country,
success: function(msg){
$("#state").html(msg);
}
});
}
function get_towns(states)
{
$.ajax({
type: "POST",
url: "towns.php", /* The state id will be sent to this file */
beforeSend: function () {
$("#town").html("<option>Loading ...</option>");
},
data: "states="+states,
success: function(msg){
$("#town").html(msg);
}
});
}
</script>
</head>
<body>
<div id="details">
<?php
$num=1;
$sql="SELECT * FROM contact";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table>
<form action="filtercat.php" method="post">
<tr>
<td>Country </td>
<td>
<select name="country" onchange="get_states(this.value)">
<option>Select Country</option>
<?php
while($rowcountry=mysql_fetch_array($resultcountry))
{
?>
<option value="<?php echo $rowcountry['country']; ?>"><?php echo $rowcountry['country']; ?></option>
<?php
}
?>
</select>
</td>
<td>State:</td>
<td id="state">
<select name="state">
<option>Select State</option>
</select>
</td>
<td>City / Town:</td>
<td id="town">
<select name="town" id="townsbox">
<option>Select City / Town</option>
</select>
</td>
<td><input type="image" name="submitcat" src="images/filter.png"></td>
</form>
</tr>
</table>
<!-- /* To display Data in the tabular form */ -->
<?php
$num=1;
$sql="SELECT * FROM contact";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table id="rounded-corner">
<form name="form1" method="post" action="delmultipleuser.php">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Email</th>
<th>Skype Id</th>
<th>Phone Number</th>
<th>Address</th>
<th>Category</th>
<th>Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="12">Total Users: <?php echo $count; ?></td>
</tr>
</tfoot>
<tbody>
<?php
while($row=mysql_fetch_array($result))
{
?>
<tr class="odd">
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" value=<?php echo $row['contactid']; ?> ></td>
<td><a href="details.php?id=<?php echo $row['contactid']; ?>"><?php echo $row['fullname']; ?></a></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['skype']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['category']; ?></td>
<td><a href="deletesinglerecord.php?id=<?php echo $row['contactid']; ?>" onclick="return confirm('Delete Record ?')"><img src="images/trash.gif"></a></td>
</tr>
<?php
}
if($count==0)
{
?>
<tr>
<td colspan="10" class="norecords">
<p>
No Records Found.
</p>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</body>
</html>
The selected values (country, state and town) which I'm trying to echo in filtercat.php....... only country is getting echoed. But state and town values are vanishing.
This is my states.php ....... to fetch states and populate in the main page...
<?php
$country = $_POST['country'];
$sql_state = "SELECT DISTINCT state FROM contact WHERE country = '$country'";
$result_state = mysql_query($sql_state);
?>
<select name="state" id="state" onchange="get_towns(this.value)">
<option>Select States</option>
<?php
while($row_state = mysql_fetch_array($result_state))
{
?>
<option value="<?php echo $row_state['state'];?>" ><?php echo $row_state['state']; ?></option>;
<?php
}
?>
</select>
And this is towns.php to fetch town and populate in the main page...
<?php
include('config.php');
?>
<?php
$states = $_POST['states'];
$sql_town = "SELECT DISTINCT town FROM contact WHERE state = '$states'";
$result_town = mysql_query($sql_town);
?>
<select name="town" id="town">
<option>Select Town</option>
<?php
while($row_town = mysql_fetch_array($result_town))
{
?>
<option value="<?php echo $row_town['town'];?>" ><?php echo $row_town['town']; ?></option>;
<?php
}
?>
</select>
Data is getting populated fine onchange of the respective dropdown list, but any idea how to pass the selected data to the backend page once i click submit ...??
I need those values for writing a further query in the backend page.
Thanx. And sorry for such a lengthy post.