Tuesday, May 22, 2012

Jquery ajax combo box – So Simple


Step 1:
Create a combo and load main category options from database, and create a combo(dropdown box) with the id selects.
<select id=”selects” name=”selects”> </select>
<script
 type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript">
<!--
function choosesub(val){
 $('#selects').html('Loading...');
 $('#selects').load('findsub.php',{value:val},function(responseText){
 //alert("Response:\n" + responseText);
 $("#selects").add(responseText);

 });
}
//-->
</script>
Step:2
Now create the ajax file to build options
<?
CateyList = $CateyDaoImpl->getAllCateyByMain($_REQUEST['value']);
foreach ($CateyList as $a){
$result_string .= “<option value=’”.$a->getId().”‘>”.$a->getName().”</option>”;
}
echo $result_string;
?>
You are done now!!!

No comments:

Post a Comment