Tuesday, April 24, 2007

Ajax select category and subcategory list automatic

//category.php


<script language = 'javascript'>

// create ajax instance

function GetXMLHttpRequest()

{

var object = null;



if (window.XMLHttpRequest) //for mozilla,safari,opera,nets..

{

object = new XMLHttpRequest();

}

else if (window.ActiveXObject) //for IE..

{

try

{

object = new ActiveXObject("Msxml2.XMLHTTP");

}

catch(e)

{

}



if (object == null)

{

try

{

object = new ActiveXObject("Microsoft.XMLHTTP");

}

catch(e)

{

}

}

}



if (object == null)

{

alert("Your browser does not support AJAX");

}



return object;

}

var httpxx = GetXMLHttpRequest();


//Ajax for Subcategories


 


var url_cat = "getsubcategory.php?cid=";


// handling ajax response

function handleHttpResponse2()

{

if (httpx.readyState == 4)

{



if(httpx.status == 200)

{



document.getElementById('prepage2').style.visibility='hidden';

var results=httpx.responseText.split(",");



var oSelect1 = document.getElementById("subcategory");

oSelect1.options.length=0;



if(results[0].length==0)

{

var oOption = document.createElement("option");

oOption.value = 0;

oOption.innerHTML = "-select-";



var oSelect = document.getElementById("subcategory");

oSelect.appendChild(oOption);

}

else

{

var oOption = document.createElement("option");

oOption.value = 0;

oOption.innerHTML = "-select-";



var oSelect = document.getElementById("subcategory");

oSelect.appendChild(oOption);

for (var d=0;d < results.length ;d++)

{

var oOption = document.createElement("option");

var dd1=results[d].split("-")

oOption.value = dd1[1];

oOption.innerHTML = dd1[0];



var oSelect = document.getElementById("subcategory");

oSelect.appendChild(oOption);

}

}

}

}

}


// make ajax request

function updateCategoryState() {

var categoryValue = document.getElementById("category").value;

httpx.open("GET", url_cat + escape(categoryValue), true);

document.getElementById('prepage2').style.visibility='visible';

httpx.onreadystatechange = handleHttpResponse2;

httpx.send(null);

}


var httpx = GetXMLHttpRequest();


</script>


//category.php file where selection is made and subcategory is updated


<td width="53%">

<select id="category" name='category' onchange="updateCategoryState();" class='welcome_text'>

<option value='0' class='welcome_text'>Select Category</option>

<?php


$query1Select = "select * from tblcategories";

$query1Result = query_select($query1Select,$nRows);

while($row = mysql_fetch_object($query1Result))

{

$categoryList.="<option value='$row->id'>$row->categoryname</option>";

}


?>

</select>


</td>


<tr>

<td class="caption" align='right' class='welcome_text'>SubCategory Name&nbsp;</td>

<td width="53%">

<select id="subcategory" name='subcategory' class='welcome_text'>

<option value='0' class='welcome_text'>Select Subcategory</option>

<?php


$query1Select = "select * from tblsubcategories";

$query1Result = query_select($query1Select,$nRows);

while($row = mysql_fetch_object($query1Result))

{

$subcategoryList.="<option value='$row->subcategoryname'>$row->subcategoryname</option>";

}


?>

</select>

<span id="prepage2" align='center' class='welcome_text'>

<font color='#FF0000'>

Loading ... ...Please wait

</font>

</span>

</td>

</tr>


 


 


//get subcategory file .php


<?php

$str="select * from tblsubcategories where categoryid=$cid";

$res=query_select($str,$conn);

$str="";

while ($fobj=mysql_fetch_object($res))

{

$str.="$fobj->subcategoryname"."-"."$fobj->id".",";

}

$str2=substr($str,0,strlen($str)-1);

echo "$str2";

?>

10 comments:

Sujitkumar said...

Nice info about Php it’s reallyhelpful…. If it possible share some more tutorials……….

Richard Swayar said...

Australia Best Tutor is one of the best Online Assignment Help providers at an affordable price. Here All Learners or Students are getting best quality assignment help with reference and styles formatting.

Visit us for more Information

Australia Best Tutor
Sydney, NSW, Australia
Call @ +61-730-407-305
Live Chat @ https://www.australiabesttutor.com




Our Services

Online assignment help Australia
my assignment help Australia
assignment help
help with assignment
Online instant assignment help
Online Assignment help Services

Riya karakoti said...

Really a good post, thanks for sharing .keep it up.

Best Web Design Training Institutes in Noida

Best Hadoop Training Institutes In Noida

Best Digital Marketing Training Institute in Noida

Sap Training Institute in Noida

Best Java Training Institute in Noida

SAP SD Training Institute in Noida

Best Auto CAD Training Institute In Noida

AutoCAD training in Noida said...

Each department of CAD have specific programmes which, while completed could provide you with a recognisable qualification that could assist you get a job in anything design enterprise which you would really like.

AutoCAD training in Noida

AutoCAD training institute in Noida


Best AutoCAD training institute in Noida

amarraj paindit said...

rpa training institute in noida
sas training institute in noida
hadoop training institute in noida
blokchain traninig institute noida


amarraj paindit said...

servicenow scripting Training in Noida
rpa training institute in noida
sas training institute in noida
hadoop training institute in noida
blokchain traninig institute noida


Arvind Rawat said...

When cooking with oil, you will see the fact that smoke usually receives emitted in case you often uses the identical oil. Typically, these form of eating places have today's hoods as well as exhaust fans.
Visit here
Kitchen Chimney Repair Service in Noida
Kitchen Kitchen Chimney Repair Service in Vaishali
Kitchen Kitchen Chimney Repair Service in indirapuram
Kitchen Kitchen Chimney Repair Service in vasundhra
Kitchen Kitchen Chimney Repair Service in faridabad

tanmay chaubey said...

Its really nice and informative.. Thanks for sharing

Microsoft Azure Training institute in Noida,

AWS Training Institute in Noida sector 16,

Cloud Computing Training Institute in noida sector 16,

Data science training institute in noida sector 16,

Data Science With machine learning training Institute in Noida sector 16,

Data Science With python training Institute in Noida sector 16,

Web-designing Training Institute in Noida sector 16,


tanmay chaubey said...

Its really nice and informative.. Thanks for sharing

software-testing Training Institute in Noida sector 16,

Digital Marketing Training Institute in noida sector 16,

hadoop Training Institute in noida sector 16,

Java Training Institute in noida sector 16,

linux Training Institute in noida sector 16,

node.js Training Institute in noida sector 16,

openstack Training Institute in noida sector 16,

Oracle DBA Training Institute in noida sector 16,

tanmay chaubey said...

Its really nice and informative.. Thanks for sharing

Php Training Institute in noida sector 16,

PlSql Training Institute in Noida sector 16,

Python Training Institute in Noida sector 16,

RPA Training Institute in Noida sector 16,

Salesforce Training Institute in Noida sector 16,

Sap fico Training Institute in Noida sector 16,

ERP Sap mm Training Institute in Noida Sector 16,

Sap Training Institute in Noida Sector 16,

SAS Training Institute in Noida Sector 16,

Blue Prism Training Institute in Noida,