title: jQuery ajax unlimited dynamic selectbox based on parent categories
body: <p>I have a table for category :</p>
  
  <pre><code>| category_id | category_name | parent_id
  | 1           | Electronics   | 0
  | 2           | Mobile Phones | 1
  | 3           | Computers     | 1
  | 4           | Iphone        | 2
  | 5           | Samsung Galaxy| 2
  | 6           | Asus Laptop   | 3
  </code></pre>
  
  <p>So this table is able to store unlimited child category for a parent category.</p>
  
  <p>Now what I'm trying to achieve is, let's say that I choose Electronics, then another selectbox should appear with value list <code>Mobile Phones</code> and <code>Computers</code>.
  And then if  I choose <code>Computers</code>, another selectbox will appear with the value list <code>Asus Laptop</code>.</p>
  
  <p>I know how to code the dynamic select box, but it doesnt work with unlimited sub-categories. </p>
  
  <p>This one should work like this (based on my thinking). </p>
  
  <blockquote>
    <ol>
    <li>User choose a category from the first selectbox</li>
    <li>Send ajax to getcategory.php</li>
    <li>getcategory.php finds out if there is any child category from the user-chosen first category.</li>
    <li>ajax receive data from getcategory.php</li>
    <li>if data exist, jQuery create a new select box and put in the fetched data into it.</li>
    <li>User choose sub-category from the just added selectbox</li>
    <li>Send ajax to getcategory.php</li>
    <li>getcategory.php finds out if there is any more child category from the user-chosen sub-category.</li>
    <li>ajax receive data from getcategory.php</li>
    <li>if data exist, jQuery create a new select box and put in the fetched data into it.</li>
    <li>and so on.. until the selectbox have no child category.</li>
    </ol>
  </blockquote>
  
  <p>How do I achieve this? Is this the right way? or Is there any other workaround for this? Thank you</p>