There are two methods for refreshing parts of web page. Unfortunately both these methods work only in IE 5.0 (and above) only.
1) Using scriptlets. The following link gives more info on this.
http://www.codeproject.com/html/topten.asp
2) using XML. This method basically involves submitting an XML through Javascript to a web page and getting the response as another XML. Then the response XML need to be parsed and results shown in page.
Here is a sample script for this. This will fetch the related fabric types when a select box entry containing fabric categories is changed.
The page :
Code:
<html>
<head>
<title>Untitled</title>
<script language="JavaScript1.2" type="text/javascript">
function func_retrieve_fabric_types()
{
var str_xml="";
//alert(document.frm_test.cbo_fabric_categories.options[document.frm_test.cbo_fabric_categories.selectedIndex].value);
if(!((document.frm_test.cbo_fabric_categories.options[document.frm_test.cbo_fabric_categories.selectedIndex].value)==""))
{
str_xml+="<xml_to_be_submitted><request_xml><fabric_cat_id>"+document.frm_test.cbo_fabric_categories.options[document.frm_test.cbo_fabric_categories.selectedIndex].value+"</fabric_cat_id></request_xml></xml_to_be_submitted>";
var obj_http=new ActiveXObject("Microsoft.XMLHTTP");
var str_url="testfb.asp";
var str_http_method="post";
obj_http.open(str_http_method,str_url,false);
obj_http.SetRequestHeader("Content-Type","application/x-www-form-urlencoded");
obj_http.send(str_xml);
var str_reply=obj_http.ResponseText;
//processes return xml
var xmlResponse = str_reply;
var objXmlDOM=new ActiveXObject("Microsoft.XMLDOM");
if(!objXmlDOM.loadXML(xmlResponse))
{
alert("Could not load xml object");
}
else
{
var i_option_id = objXmlDOM.selectNodes("/options/option_id");
var str_option_text = objXmlDOM.selectNodes("/options/option_text");
var i_loop;
var i_num_options=1;
document.frm_test.cbo_fabric_types.options.length=1;
for(i_loop=0;i_loop<i_option_id.length;++i_loop)
{
document.frm_test.cbo_fabric_types.options.length+=1;
i_num_options++;
document.frm_test.cbo_fabric_types.options[i_num_options-1].value=i_option_id[i_loop].text;
document.frm_test.cbo_fabric_types.options[i_num_options-1].text=str_option_text[i_loop].text;
}
}
}
}
</script>
</head>
<body>
<form name="frm_test" method="post">
<select name="cbo_fabric_categories" onChange="func_retrieve_fabric_types()">
<option value="">Please select from below</option>
<%
Response.Write(func_fill_combo(cnn_test, "tbl_fabric_cats", "FABRIC_CAT_ID", "FABRIC_CAT_NAME",""))
%>
</select>
<br><br><br>
<select name="cbo_fabric_types">
<option value="">Please select from below</option>
</select>
</form>
</body>
</html>
The page (testfb.asp) which fetches related fabric types is below.
Code:
<%
dim obj_xml_dom
dim str_xml
set obj_xml_dom = Server.CreateObject("Microsoft.XMLDOM")
str_xml = Request.Form
if (not(obj_xml_dom.loadXML(str_xml))) then
Response.Write("No XML")
end if
dim obj_xml
set obj_xml=obj_xml_dom.documentElement.childNodes.item(0)
dim iCategoryId
iCategoryId=obj_xml.text
dim str_reply
dim qry_traverse_fabric_types
dim rst_traverse_fabric_types
qry_traverse_fabric_types="SELECT FABRIC_ID, FABRIC_NAME FROM tbl_fabrics WHERE FABRIC_CAT_ID=" & iCategoryId
set rst_traverse_fabric_types=Server.CreateObject("ADODB.RecordSet")
rst_traverse_fabric_types.Open qry_traverse_fabric_types, cnn_test
if(not(rst_traverse_fabric_types.Eof or rst_traverse_fabric_types.Bof)) then
str_reply="<options>"
rst_traverse_fabric_types.MoveFirst
while(not(rst_traverse_fabric_types.Eof))
str_reply=str_reply & "<option_id>" & rst_traverse_fabric_types("FABRIC_ID") & "</option_id>"
str_reply=str_reply & "<option_text>" & rst_traverse_fabric_types("FABRIC_NAME") & "</option_text>"
rst_traverse_fabric_types.MoveNext
wend
str_reply=str_reply & "</options>"
else
str_reply=""
end if
Response.Write(str_reply)
%>
Regarding the risk associated with this. As you can see testfb.asp page can return this value when any web page or other application (
VB, C) submits the XML of the required format to it. I don't know how can we make this secure (so that it will accept only XML from a particular page). May be some other parson can suggest a method.
the function func_fill_combo is for filling a select box from database.
Hope this helps.