Nov 26

In many web site we have seen that on selecting country,
state or city list is updated.
In this article i am showing how to update children select list on changing parent list.
To do this i am using jquery and ruby on rails.although it will works for almost all languages
For this article, I am updating city list on changing states.
So one state has many cities,and city belongs to state.

   <script type="text/javascript" src="jquery.js"></script>
   <script type="text/javascript">
     state_id = $("#states").val();
       type: "GET",
       url: "/",
        /*or any server side url which generate citylist for rails
                 "/states/city_list"or<%= city_list_states_path%> */
      data: "state_id="+state_id,
       /*here we are passing state_id to server based on that on
             he can find out  all the city related to that states */
     success: function(html){
      /*html content response of */
 <div id="state_list">
   <select id="states">
 <div id="city_list">
   <select id="cities">
   <option value="1">aa</option>
   <option value="2">aaa</option>

and gives following html
on processing state id which we have pass as state_id

<select id="cities">
  <option value="3">bb</option>
  <option value="4">bbb</option>

I have updated source code

Aug 10

Here it is how we can do that magic,

if( isset($_GET[‘function’]) ) {
switch( $_GET[‘function’] ) {
case ‘dosomething’:
case ‘dosomethingelse’:

And then link to script.php?function=dosomething

url rewriting

Benifit :

When a search engine visits the dynamic url like product.php?id=test it does not give much importance to that URL as search engine sees “?” sign treat it as a url which keeps on changing. so we’re converting the dynamic URL like the product.php?id=test to static url format like product-test.html. We’ll rewrite the url in such a way that in browser’s address bar it will display as a product-test.html but it actually calls the file product.php?id=test. So that why these kind of URL also named as SEO friendly URL.

How to do using Apache ?

To rewrite the URL you must have the mod_rewrite module must be loaded in apache server. And furthermore, FollowSymLinks options also need to be enabled otherwise you may encounter 500 Internal Sever Error.

The Procedure

For rewriting the URL, you should create a .htaccess file in the root folder of your web directory. And have to put the following codes as your requirement.

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [nc]

The following example will rewrite the test.php to test.html i.e when a URL like is called in address bar it calls the file test.php. As you can see the regular expression in first part of the RewriteRule command and $1 represents the first regular expression of the part of the RewriteRule and [nc] means not case sensitive.

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ products.php?id=$1

The following example will rewrite the product.php?id=test to porduct-test.html i.e when a URL like http://railstech/product-test.html calls product.php?id=test automatically.

Tagged with:
preload preload preload