Hi
Thanks for the support.
I could able to progress better.
I have three dropdowns , a textbox, two buttons.
On page load none of the dropdowns have values.
On click of categories button first dropdown gets values with "arts and science,sports,movies etc"
On change of first dropdown second dropdown gets values.On change of second third dropdown gets values.
Upto this I completed.
Now user searches for a text and clicks on search button. I was struck up here as I dont know how to write the query here.
Based on the third dropdown and the textbox inputs I have to show the result with autocomplete feature too.
How to do that?
I am providing my code below:
<script type="text/javascript" src="metaweb.js"></script>
<script type="text/javascript" src="json.js"></script>
<script>
function LoadCategories()
{
divList.innerHTML = "Loading..."
var query = [{ name: null, type: '/freebase/domain_category' }];
Metaweb.read(query, displayCategories);
function displayCategories(result)
{
if (!result)
{
divList.innerHTML = "Unknown:";
return;
}
divList.innerHTML = "";
for(var i = 0; i < result.length; i++)
{
addOption(document.getElementById('drpCategoryValues'),result[i].name, result[i].name);
}
}
}
function addOption(selectbox,text,value)
{
var optn = document.createElement("OPTION");
optn.text = removeJunk(text);
optn.value = removeJunk(text);
selectbox.options.add(optn);
}
function removeJunk(text)
{
if(text.search(/&/)>0)
{
text = text.replace(/amp;/,"");
}
return text;
}
function removeAllOptions(selectbox)
{
for(var i= selectbox.options.length-1;i>=0;i--)
{
selectbox.remove(i);
}
}
function LoadSubCategories()
{
var selectedValue = document.getElementById('drpCategoryValues').value;
var query = [{ domains:[], name: selectedValue, type: '/freebase/domain_category' }];
Metaweb.read(query, displayNames);
function displayNames(result)
{
if (!result)
{
divList.innerHTML = "Unknown";
return;
}
divList.innerHTML = "";
removeAllOptions(document.getElementById('drpSubCategoryValues'))
for(var i = 0; i < result[0].domains.length; i++)
{
addOption(document.getElementById('drpSubCategoryValues'),result[0].domains[i], result[0].domains[i]);
}
}
}
function LoadTypes()
{
debugger;
var selectedValue = document.getElementById('drpSubCategoryValues').value;
var query = [{ types:[{name:null}],name: selectedValue, type: '/type/domain' }];
Metaweb.read(query, displayTypes);
function displayTypes(result)
{
if (!result)
{
divList.innerHTML = "Unknown";
return;
}
divList.innerHTML = "";
removeAllOptions(document.getElementById('drpTypes'))
for(var i = 0; i < result[0].types.length; i++)
{
addOption(document.getElementById('drpTypes'),result[0].types[i].name, result[0].types[i].name);
}
}
}
function Search()
{
}
</script>
<html>
<head>
</head>
<body>
<div id="divList">
</div>
<select id="drpCategoryValues" size=5 runat="server" onchange="LoadSubCategories(this);"></select>
<input type="button" value="Categories" id="btn" onclick="LoadCategories()"/>
<select id="drpSubCategoryValues" size=5 runat="server" onchange="LoadTypes(this);"></select>
<select id="drpTypes" size=5 runat="server"></select>
<input type="text" id="txtSearch" />
<input type="button" value="Search" id="btnSearch" onclick="Search()"/>
</body>
</html>
Thanks & Regards,
Sreedhar Ambati