Display dropdown box with checkbox - php

<select name="city[]" id="CitySD" class="select required" multiple>
<option value=""><?php echo $this->Lang["SEL_COUNTRY"]; ?></option>
<?php
foreach ($this->all_city_list as $c)
{
?>
<option <?php
if (isset($this->userPost['city']))
{
if ($c->city_id == $this->userPost['city'])
{
?> selected <?php
}
}
?> title="<?php echo $c->city_name; ?>"value="<?php echo $c->city_id; ?>">
<?php echo $c->city_name; ?>
</option>
<?php } ?>
</select>
Above is my city drop down field in registration page,if user select country means then only the city filed gets active and its display city based on user selection country.
I want to display cities in the city drop down with individual checkbox option for all cities and select all option check box,the user can click select all means it will select all cities and deselect means it will deselect all cities and user can also select random cities.
please anyone can help me!

Related

Drop down list not populating (PHP/Myadmin)

I am trying to get a dropdown list to populate. I have two tables, a registration table and a studentclasses table. I am looking to populate the dropdown list from the class table, as a field entry in the registration table. My code is as follows:
<p>Class: <select name="classID">
<?php $classlist_sql="SELECT * FROM studentclasses";
$classlist_qry=mysqli_query($dbconnect, $classlist_sql);
$classlist_rs=mysqli_fetch_assoc($classlist_qry);
do { ?>
<option value="<?php echo $classlist_rs['classID']; ?>"
<?php
if($classlist_rs['classID']==$_SESSION['signuptest']['classID']) {
echo "selected=selected";
}
?>
><?php echo $classlist_rs['classcode']; ?></option>
<?php } while ($classlist_rs=mysqli_fetch_assoc($classlist_qry));
?></select>
</p>
My Studentclasses table has the fields classID and classcode, and I am wanting the classcode to appear in the drop down.
Any help would be greatly appreciated.

Populate table data from databse table on selecting a particuar item from drop down list?

I want to populate table data from database table "onchange" event for a dropdown list. Dropdown list itself contains data from that table but it only contains one column value. When user selects any of the item from that drop down list then all columns and its values should be displayed that belong to that particular value of selected item from drop down list.
Below is the code to only display dropdown list.
<?php
include_once("session.php");
include_once("functions.php");
include_once("connection.php");
$employername=$_SESSION["username"];
$sql = "select job_name from job_info where username=$employername";
$result = $conn->query($sql);
?>
<div>
<select name="ddljobname">
<?php while($row=$result->fetch_assoc()){ ?>
<option value="<?= $row['job_name'] ?>"><?= $row['job_name'] ?> </option>
<?php }?>
</select>
</div>
<select name="ddljobname" id="getdata">
<?php while($row=$result->fetch_assoc()){ ?>
<option value="<?= $row['job_name'] ?>"><?= $row['job_name'] ?> </option>
<?php }?>
</select>
Onchange Function :
$('#getdata').change(function(){
var jobNum = $(this).val();
//call your ajax
});

post value one dropdown to other dropdown using php mysql

include('connection.php');
$con=mysql_query("select * from province"); ?>
<select name="pid" style="float:left; width:135px;">
<option value="">Select Country</option>
<?php while($row=mysql_fetch_array($con)) {
$pid=$row['province_id'];
?>
<option value="<?=$pid?>" ><?php echo $row['province_name'] ?>
</option>
<?php } ?>
</select> -
<?php
$pid=$_POST['$pid'];
include('connection.php');
$con=mysql_query("select * from city where city_state ='$pid' ") or die(mysql_error()); ?>
<select name="cid" style="float:left; width:135px;">
<option value="">Select City</option>
<?php while($row=mysql_fetch_array($con)) {
$cid=$row['city_id'];
?>
<option value="<?=$cid?>" ><?php echo $row['city_name'] ?> <?php }?>
</option>
</select>
first table is country table, that coutry id is province_id,
second table is city, that Province id is city_state,
so, post value one to another dropdown
For this, you could use AJAX. In your country dropdown box, just echo all the countries in <option> elements.
Then attach a change event on this dropdown box using jQuery, so that it will take the user's input (I mean selected country) and do an AJAX request(jQuery has various shorthand methods for AJAX too) to fetch all the provinces belonging to this country. So this request will be sent to a PHP page on your site, that will pull the details from your db using the country id that the user selected.
Then the result from the AJAX request, which would be list of provinces with their IDs is dynamically appended to the second dropdown box(ie. for province). And for this province dropdown box also you would attach a change event to it, and do the similar thing like I mentioned above to fetch all the cities under this province, using AJAX.
Do a quick research on AJAX, in Google. There are lots of tutorials to help you.

osclass Cities dropdown based on Region Select

Im using osclass for a local classifieds website and im facing the following problem. I need to import 12 regions and 7000 cities/villages.
In the main.php im using a horizontal search bar with fields search text, categories (dropdown), Regions (dropdown), City (dropdown), Max price(text) and min Price (text)
For the Regions and Cities im using the code in inc.search.php
<?php $aRegions = Region :: newInstance()->listAll();?>
<?php if (count($aRegions) > 0) {?>
<select name="sRegion" id="sRegion">
<option value="">Select a Region</option>
<?php foreach ($aRegions as $region) {?>
<option value="<?php echo $region['s_name'];?>"><?php echo $region['s_name'];?> </option>
<?php } ?>
</select>
<?php } ?>
<?php $aCities = City::newInstance()->listAll(); ?>
<?php if(count($aCities) > 0 ) { ?>
<select name="sCity" id="sCity">
<option value="">Select a city</option>
<?php foreach($aCities as $City) { ?>
<option value="<?php echo $City['s_name'] ; ?>"><?php echo $City['s_name'] ; ?></option>
<?php }?>
</select>
<?php }?>
The problem is that the above code brings all cities when page loads and does not check what region is selected first. That means that the city dropdown will be filled with 7000 cities/villages when page loads.
I tried to remove lines
<?php foreach($aCities as $City) { ?>
<option value="<?php echo $City['s_name'] ; ?>"><?php echo $City['s_name'] ; ?></option>
<?php }?>
so when page loads, the city dropdown is empty but i dont know how to fill the dropdown with cities depend on region select.
The solution to how to use region/city in search form is described here http://forums.osclass.org/jobs/cities-dropdown-based-on-region-select/

how do i trigger the javascript event with dropdown and change the values?

I am creating a form where the users will have to select the country from the drop down list. as soon as they selects it should activate another drop down list where it should show the states belonging to the country and hence it should process the value from country Id of element. and as soon as the user selects the states another drop down list should activate listing the cities belonging to that particular states, and hence so on to areas.
for that i have written the php and html code like this.
Select Countries : <select name="countries"><br/>
<?php
foreach($property->getAllCountries() as $countries)
{
?>
<option value="<?php echo $countries['id']; ?>"><?php echo $countries['name']; ?></option>
<? } ?>
</select><br/>
Select State : <select name="state">
<?php
foreach($property->getStatesFromCountryId($countryId) as $states)
{
?>
<option value="<?php echo $states['id']; ?>"><?php echo $states['name']; ?></option>
<? } ?>
</select>
the javascript should automatically insert $countryId from and populate the states after the user selects it.
i am noob at javascript i would appreciate if someone could guide me how to achieve this?
thank you.
sorry for bad english.
you should add onchange="showstates()" to select countries and a div to add states of country to it
function showstates()
{
var country=document.getElemtById("countries").value;
if (country=="anywhere")
{
document.getElemtById("statesofcountries").innerHTML='<div>"states list"</div>';
}
}
check this link
You can always google it up:
http://roshanbh.com.np/2007/12/change-dropdown-list-options-values-from-database-with-ajax-and-php.html

Categories