views:

79

answers:

1

I have one drop down box,which represents company name.I want another drop down box depending on company selected,which represent project for that particular company. Can any 1 help me out.

Here's the code

      <tr><td align="right" valign="top" style="text-align:right"><strong>Company:</strong></td>
      <td align="left" valign="top" >`<select name= "proj" onChange="top.location =' {$smarty.server.PHP_SELF}'" ><option value='null'>all</option>`
 {assign var='cid' value='0'}


    {foreach from=$companyname item=p}



    {if  $p.cid != $cid}
       {assign var='cid' value=$p.cid}
        {html_options values=$p.cid output=$p.pname selected=$p.pname}{/if}
      {/foreach}
    </select>

 </td></tr>`

    <tr>
  <td align="right" valign="top" style="text-align:right"><strong>Project:</strong></td>
  <td align="left" valign="top" > 
   <select name= "comp"  >
  <option value='null'>all</option> 

 {if $p.pname != "" && $p.pname !="null"}

  {foreach from=$companyname item=p}

    {html_options values=$p.pname output=$p.name}
  {/foreach}{/if}
</select>
 </td></tr>

Its not properly formatted,but hope one can understand it. Thanks for help.

A: 

For your problem you need Ajax solution. You can try using javascript frameworks which have simple ajax methods, one of my favorite is jQuery. Using jQuery you can simply trigger an ajax function to submit the selected company id to a server file where you can fetch the list of other options and using a callback function you can populate the second dropdown menu.

Raf