will pay $10 paypal.what is wrong with my HTML menu using Ajax to load php include

Discussion in 'Programming' started by jasso, Aug 15, 2009.

  1. #1
    Hello experts.


    I am using a HTML menu in a php file.

    When a menu item is clicked (mouse onclick ) java function will process the menu item "ID" and will pass it to a PHP file which will query MYSQL database and will return results.

    I don't want to reload the entair PHP page, just the section that displays results based on menu selection. So Ajax is used.

    Can somebody please help....

    How to pass string 'value' to java function from a menu item?


    HTML Menu:

    <script type="text/javascript" src="clienthint.js"></script>

    <div class="h_mnu_01">
    <ul>
    <li><a href="" onclick="showreport('FA')">Featured Ads</a></li>
    <li><a href="" onclick="showreport('FE')">Featured Events</a></li>
    <li><a href="" onclick="showreport('UE')">Upcoming Events</a></li>
    <li><a href="" onclick="showreport('LA')">Latest Ads</a></li>
    </ul>
    </div>

    <br />
    <div id="Report"><b>The report will be display here.</b></div>




    Javascript file: clienthint.js


    var xmlhttp

    function showreport(str)
    {
    if (str.length==0)
    {
    document.getElementById("report").innerHTML="";
    return;
    }
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
    alert ("Your browser does not support XMLHTTP!");
    return;
    }
    var url="gethint.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    }

    function stateChanged()
    {
    if (xmlhttp.readyState==4)
    {
    document.getElementById("report").innerHTML=xmlhttp.responseText;
    }
    }

    function GetXmlHttpObject()
    {
    if (window.XMLHttpRequest)
    {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
    }



    PHP file: gethint.php

    <?php

    //get the q parameter from URL
    $q=$_GET["q"];

    // include php files that queries database and echo results
    if (strlen($q) > 0)
    {
    switch ($q)
    {
    case "FA":
    <?php include_once("featured_ads.inc.php"); ?>
    break;
    case "FE":
    <?php include_once("featured_event.inc.php"); ?>
    break;
    case "UE":
    <?php include_once("upcoming_featured_events.inc.php"); ?>
    break;
    case "LA":
    <?php include_once("latest.inc.php"); ?>
    break;
    default:
    echo "Nothing to Display !";
    }
    ?>




    1 of the PHP Include file: latest.inc.php

    <?php

    echo "result from Mysql query"

    ?>
     
    jasso, Aug 15, 2009 IP
  2. bm4web

    bm4web Well-Known Member

    Messages:
    718
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    hi,

    i can help you for this, please let me know, also look at the PM that i hve sent you :cool:
     
    bm4web, Aug 15, 2009 IP
  3. dixithdev_89

    dixithdev_89 Greenhorn

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    hi i can help you with this code i will fix it for you for 30$
     
    dixithdev_89, Aug 18, 2009 IP