Adding customer reviews to product page
Using the AJAX (Asynchronous Javascript and XML) technology, you can add the customer reviews page to the products page simply by adding some code to the product template file (tmp_product.htm) and modifying the review adding and listing page (shopreviewadd.asp and shopreviewlist.asp). For precaution, please make a backup of all the aforementioned files before proceeding with the change.
1. Add the following Javascript to the product template file (tmp_product.htm) just under [ADD_PAGEHEADER] on line 1:
script language="javascript"> var xmlHttp
function showReview(str) { if (str.length==0) { document.getElementById("review").innerHTML="" return }
xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { return } var url="shopreviewlist.asp" url=url+"?id="+str url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) }
function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("review").innerHTML=xmlHttp.responseText } }
function GetXmlHttpObject() { var objXMLHttp=null if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest() } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp } showReview("[catalogid]")
/script>
2. After adding the bulk of the code, you need to specify where to put the customer reviews. Locate where you want to put it and add the following:
div id="review"> /div>
3. As the existing shopreviewlist.asp page is a stand-alone page, it will show the header and footer if you view the changes you have made now. Locate line 28 and 31:
ShopPageHeader ShopPageTrailer
Add ' in front of both lines to comment them out.
4. In the same file, it also displays the product name, "Write Review" and "Product Details" link; as they are now integrated into the products description page, they no longer need to be shown. Locate lines 156-158:
Response.write ReviewHeader & Productname AddHyperlinks Response.write ReviewHeaderEnd
As in step 3, add ' in front of all three lines so that they will no longer be shown.
5. If you test this now, it will show the reviews for the product, however, if you add a review now, you will notice that it directs to the shopreviewlist.asp page which now has no headers and footers. Instead, you will want it to redirect to the product display page. To do this, open shopreviewadd.asp and locate line 105 and 107:
Responseredirect "shopreviewlist.asp?id=" & catalogid & "&msg=Yes" Responseredirect "shopreviewlist.asp?id=" & catalogid
Change both lines to "shopexd.asp": Responseredirect "shopexd.asp?id=" & catalogid & "&msg=Yes" Responseredirect "shopexd.asp?id=" & catalogid
Times Viewed:
3700 |
Added By:
Joseph Chang |
Date Created:
11/28/2006 |
Last Updated:
2/11/2008 |
|