Popular Posts

Sep 18, 2011

How to load data in a combobox without reloading the page from other page in PHP



Write the code in page a.php
<select name="company_id" id="company_id" >
                                                   <option></option>
                                                  
                                                   <?php
                                                   $getCompany = "select customer_id, company_name from customer WHERE customet_type = 1";
                                                   $getCompanyResult = mysql_query($getCompany);
                                                   while($getCompanyRows = mysql_fetch_object($getCompanyResult)){
                                                   ?>
                                                   <option value="<?php echo $getCompanyRows->customer_id ; ?>" <?php if($getCompanyRows->customer_id == $var->company_id){ echo "selected"; } ?> ><?php echo $getCompanyRows->company_name ; ?></option>
                                                  
                                                   <?php
                                                   }
                                                   ?>
                                                   </select>
<a href="#" onClick="window.open('b.php?hide_menu=1','popup','width=960,height=530,scrollbars=no,scrollbars=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=300,top=300'); return false">Add New Data</a>

In Page B:
Write some code to insert the data in database.
<script language="javascript">
//alert(window.opener.document.getElementById('company_id').value);
var optionstr = '<option></option>';
   <?php
   $getCompany = "select customer_id, company_name from customer WHERE customet_type = 1";
   $getCompanyResult = mysql_query($getCompany);
   while($getCompanyRows = mysql_fetch_object($getCompanyResult)){
   ?>
   optionstr +='<option value="<?php echo $getCompanyRows->customer_id ; ?>"><?php echo $getCompanyRows->company_name ; ?></option>';
   <?php
   }
   ?>
window.opener.document.getElementById('company_id').innerHTML= optionstr;
</script>


No comments:

Post a Comment