2

I have a class named "Example" and has following methods printProduct(),printCategory(). The printProduct has an anchor tag which has call to javascript function through onclick and using Ajax I call a PHP page where I pass the value of current product.

private function _printProductLinks ($value_selected) {
        $html = "";
        $html .= "<ul class=\"tabs\">";
        for($i=0; $i<count($this->_productArray); $i++) {
            if($this->_productArray[$i]->_productId == $value_selected) {
                $html .= "<li><a onclick=\"gotoProduct(".$this->_productArray[$i]->_productId.")\" id=\"selected\">" .$this->_productArray[$i]->_productName."</a></li>";

            }else {
                $html .= "<li><a onclick=\"gotoProduct(".$this->_productArray[$i]->_productId.")\">" .$this->_productArray[$i]->_productName."</a></li>";
            }
        }
        $html .= "</ul>";
        return $html;
    }

private function _printCategoryLinks () {
        $html = "";
        $html .= "<ul class=\"tabs\">";
        for($i=0; $i<count($this->_categoryArray); $i++) {
            if($this->_categoryArray[$i]->_categoryId == $this->_currentCategory) {
                $html .= $this->return_nbsp(2)."<li><a onclick=\"gotoCategory(".$this->_currentProduct.",".$this->_categoryArray[$i]->_categoryId.")\" id=\"selected\">" .$this->_categoryArray[$i]->_categoryName."</a></li>";

            }else {
                $html .= $this->return_nbsp(2)."<li><a onclick=\"gotoCategory(".$this->_currentProduct.",".$this->_categoryArray[$i]->_categoryId.")\">" .$this->_categoryArray[$i]->_categoryName."</a></li>";
            }
        }
        $html .= "</ul>";
        $html .= $this->_printSubCategoryLinks();
        return $html;
    }

and the javascript gotoProduct() is as follows

function gotoProduct(product_id){
    try{
        var xmlHttp = createXmlHttpRequestObject();
        var jsonstring = "product=" +encodeURIComponent(product_id);
        xmlHttp.open("POST", "dp_entry.php", true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", jsonstring.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.onreadystatechange = function(){
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
               // var jsondata = xmlHttp.responseText;
            }
        }
        xmlHttp.send(jsonstring);
    } catch (e){
        alert("Can't connect to server:\n" + e.toString());
    }
}

so,on executing the printProductlinks() will call javascript function gotoproduct(product_id) and then has to print the categories using _printcategories() under the products

5
  • 3
    I'm confused. What was the question exactly? Commented Mar 7, 2011 at 7:07
  • After executing the gotoProduct() the printCategoryLinks() should get executed. Commented Mar 7, 2011 at 7:17
  • 1
    god damnit, provide some PHP and JS code, we can't know what you're doing just like that ... Commented Mar 7, 2011 at 10:55
  • Where does printCategoryLinks() get called? Inside dp_entry.php? If so then we need to see that as well Commented Mar 7, 2011 at 11:11
  • That is php function should be called from javascript function gotoproduct() Commented Mar 7, 2011 at 11:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.