<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bagesh Singh&#039;s Blog &#187; dropdown</title>
	<atom:link href="http://www.bageshsingh.com/bagesh-blog/tag/dropdown/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bageshsingh.com/bagesh-blog</link>
	<description>Shortest Distance to  Web Solutions &#38; Software Solutions</description>
	<lastBuildDate>Wed, 22 Feb 2012 18:42:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Change dropdown list (options) values from database with ajax and php</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/01/change-dropdown-list-options-values-from-database-with-ajax-and-php-4/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/01/change-dropdown-list-options-values-from-database-with-ajax-and-php-4/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 14:27:27 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ajax dropdown]]></category>
		<category><![CDATA[dropdown]]></category>
		<category><![CDATA[php ajax]]></category>
		<category><![CDATA[php ajax dropdown]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1058</guid>
		<description><![CDATA[I’m going to show you a example in php and ajax to change the values of the dropdown’s options without refreshing the page. The values (options) of the dropdown are fetched from the database and the certain portion of the web pages is only refreshed without need to refresh the whole page. Let’s start with [...]]]></description>
			<content:encoded><![CDATA[<p>I’m going to show you a example in php  and ajax to change the values of the dropdown’s options without  refreshing the page. The values (options) of the dropdown are fetched  from the database and the certain portion of the web pages is only  refreshed without need to refresh the whole page.<br />
Let’s start with creating the two tables country and city and insert some data</p>
<blockquote>
<pre>CREATE TABLE country
(
   id tinyint(4) NOT NULL auto_increment,
   country varchar(20) NOT NULL default '',
   PRIMARY KEY  (id)
) TYPE=MyISAM;CREATE TABLE city
(
  id tinyint(4) NOT NULL auto_increment,
  city varchar(50) default NULL,
  countryid tinyint(4) default NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;</pre>
</blockquote>
<p>Now let’s look at the html code, let’s look at the code of the form and its elements</p>
<blockquote>
<pre>&lt;form method="post" action="" name="form1"&gt;
Country : &lt;select name="country" nChange="getCity('findcity.php?country='+this.value)"&gt;
 &lt;option value=""&gt;Select Country&lt;/option&gt;
 &lt;option value="1"&gt;USA&lt;/option&gt;
 &lt;option value="2"&gt;Canada&lt;/option&gt;
     &lt;/select&gt;
&lt;br /&gt;City : &lt;div id="citydiv"&gt;
 &lt;select name="select"&gt;
 &lt;option&gt;Select City&lt;/option&gt;
     &lt;/select&gt;
 &lt;/div&gt;
&lt;/form&gt;</pre>
</blockquote>
<p>As you can see that when the dropdown named “country” is changed the  “getCity” function is called. Look at the other dropdown carefully, it  is inside the division called “citydiv”.</p>
<p>Now let’s look at the javascript function called “getCity”</p>
<blockquote>
<pre>function getCity(strURL)
{
 var req = getXMLHTTP(); // fuction to get xmlhttp object
 if (req)
 {
  req.onreadystatechange = function()
 {
  if (req.readyState == 4) { //data is retrieved from server
   if (req.status == 200) { // which reprents ok status
     document.getElementById('citydiv').innerHTML=req.responseText;
  }
  else
  {
     alert("There was a problem while using XMLHTTP:\n");
  }
  }
  }
req.open("GET", strURL, true); //open url using get method
req.send(null);
 }
}</pre>
</blockquote>
<p>now we’ve to create the file called findcity.php and put the following PHP code</p>
<blockquote>
<pre>&lt;? $country=$_GET['country'];
$link = mysql_connect('localhost', 'root', ''); /change the configuration if required
if (!$link) {
  die('Could not connect: ' . mysql_error());
}
mysql_select_db('db_ajax'); //change this if required
$query="select city from city where countryid=$country";
$result=mysql_query($query);?&gt;
&lt;select name="city"&gt;
&lt;option&gt;Select City&lt;/option&gt;
&lt;? while($row=mysql_fetch_array($result)) { ?&gt;
   &lt;option value&gt;&lt;?=$row['city']?&gt;&lt;/option&gt;
&lt;? } ?&gt;
&lt;/select&gt;</pre>
</blockquote>
<p>Thats all, whenever you change the  dropdown of country the values of the city dropdown is automaticalled  changed without refreshing the page.<br />
If you want to download full source code, <a href="http://www.roshanbh.com.np/ajax_php_dropdown.zip"><strong>Click here to download</strong></a><strong>.</strong></p>
<p><strong>Security Note :</strong> If you want to use this code in your project then there is a security flaw in the PHP code, please use $country=intval($_GET['country']); in the php code instead of $country=$_GET['country']; in the findcity.php to prevent your site from sql injection attack.</p>
<div id="seo_alrp_related"><h2>Posts Related to Change dropdown list (options) values from database with ajax and php</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/change-dropdown-list-options-values-from-database-with-ajax-and-php-3/" rel="bookmark">Change dropdown list (options) values from database with ajax and php</a></h3><p>I’m going to show you a example in php and ajax to change the values of the dropdown’s options without refreshing the page. The values ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/change-dropdown-list-options-values-from-database-with-ajax-and-php-2/" rel="bookmark">Change dropdown list (options) values from database with ajax and php</a></h3><p>I’m going to show you a example in php and ajax to change the values of the dropdown’s options without refreshing the page. The values ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/02/populate-triple-drop-down-list-from-database-using-ajax-and-php/" rel="bookmark">Populate triple drop down list from database using Ajax and PHP</a></h3><p>I’ve got many email from people asking for populating triple drop down list from the database without refreshing page using Ajax and PHP after posting ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/getting-country-city-name-from-ip-address-in-php-3/" rel="bookmark">Getting country , city name from IP address in PHP</a></h3><p>esterday, miaki asked me how can we get the country name from the IP address in PHP. Today, I’ve come up with the answer of ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/getting-country-city-name-from-ip-address-in-php-4/" rel="bookmark">Getting country , city name from IP address in PHP</a></h3><p>Yesterday, Miky  asked me how can we get the country name from the IP address in PHP. Today, I’ve come up with the answer of ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/01/change-dropdown-list-options-values-from-database-with-ajax-and-php-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>38 jQuery And CSS Drop Down Multi Level Menu Solutions</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/07/38-jquery-and-css-drop-down-multi-level-menu-solutions/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/07/38-jquery-and-css-drop-down-multi-level-menu-solutions/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 15:54:42 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[coding technique]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[dropdown]]></category>
		<category><![CDATA[Menu]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[webdesign]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=611</guid>
		<description><![CDATA[Hello again, it Posts Related to 38 jQuery And CSS Drop Down Multi Level Menu SolutionsSexy Drop Down Menu w/ jQuery &#038; CSSStudies show that top navigations tend to get the most visual attention when a user first visits a site. Having organized and intuitive navigation is ...Create a Transparent jQuery UI AutoComplete MenuLet us [...]]]></description>
			<content:encoded><![CDATA[<p>Hello again, it</p>
<div id="seo_alrp_related"><h2>Posts Related to 38 jQuery And CSS Drop Down Multi Level Menu Solutions</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/07/sexy-drop-down-menu-w-jquery-css/" rel="bookmark">Sexy Drop Down Menu w/ jQuery &#038; CSS</a></h3><p>Studies show that top navigations tend to get the most visual attention when a user first visits a site. Having organized and intuitive navigation is ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/create-a-transparent-jquery-ui-autocomplete-menu/" rel="bookmark">Create a Transparent jQuery UI AutoComplete Menu</a></h3><p>Let us quickly see how to create a Transparent jQuery UI AutoComplete Menu. Here’s some code to implement the AutoComplete Menu. We will make it ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/how-to-disable-context-menu-in-browsers/" rel="bookmark">How to disable context menu in browsers ?</a></h3><p>Today, I would like to share a fairly simple technique to disable right click menu of the website. I was using around 10-15 lines of ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/02/sleek-and-smooth-animated-menu-using-jquery/" rel="bookmark">Sleek and Smooth animated menu using jQuery</a></h3><p>Today, I</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/07/38-jquery-and-css-drop-down-multi-level-menu-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

