SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic ajax page loaded by html dropbox

    I'm building a page where users can write reviews about music/video/... I would like to build a dynamic page, that shows different options for different categories. This page would be loaded by a html dropbox. I though the Onchange option would work perfect for this.

    My website is made with a template system, so my html and php are in seperate files. This should not make a big problem though. I was thinking about making the dropbox send a value to the review.php, and the php would $_GET the category and switch cases for each category. For each case, i would send a true value to the html template. Example:

    PHP Code:
    if (isset($_GET['category'])){
      switch(
    $_GET['category']){

    case 
    '1' :
    $reviewtpl->set("video",true,true);
    break;

    //and the rest of the cases...
      
    }

    the video part of the review template would in this case look something like this:

    HTML Code:
    <if:video>
    code that i want to load if video is selected in the dropbox
    </if:video>
    I'm pretty sure that i got my php and html part correct, the only problem seems to be the javascript function that loads the dropbox option and sends it to review.php. I got 2 functions for this:


    Code JavaScript:
    function getHTTPObject(){
      if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
      else if (window.XMLHttpRequest) return new XMLHttpRequest();
      else {
        err_msg("Page requires javascript.");
        stdfoot();
        exit();
      }
    } 
     
    function getCategory(){
      httpObject = getHTTPObject();
      if (httpObject != null) {
        httpObject.open("GET", "review.php?category="+document.getElementById('category').value, true);
        httpObject.send(null);
      }
    }

    I'm not very good at javascript, and these are just some functions which i found and changed to my needs. But as you may expect, they do not work. I feel like there is something missing but i'm not sure what. Would anyone know what's missing, or know a different way of doing what i want?

    PS: i hope i'm making any sense, it's kinda hard to explain

  2. #2
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll have to change tactics. I can't use this method because it requires the html to refresh at onchange, and that would take away the point of a dynamic page. I'm now experimenting with grabbing the pagecontent from an external file.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •