SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Loading Data using ComboBox

    Hi guys, I'm stuck, I don't know what is the error on my code but I guess, I made it correct. I am loading a data using combo box through AJAX below are my codes.

    my AJAX Script
    Code:
    function loadawardsdetail(strID)
    {
      var aHttpRequest;
      
      if(window.XMLHttpRequest)
        aHttpRequest=new XMLHttpRequest();
      else
        aHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
        
      aHttpRequest.onreadystatechange = function()
      {
        if((aHttpRequest.readyState == 4) && (aHttpRequest.status == 200))
        {
          var list = document.getElementById('grid');
          list.innerHTML = aHttpRequest.responseText;
        }
        
        aHttpRequest.open(GET,"ajaxloadawards.php?id="+strID,true);
        aHttpRequest.send();
      }
    }
    award.php
    Code:
    <form method="post">
              <label class="label_s">Competition Details:</label>
              <select name="cboCompetitionID" id="cboCompetitionID" class="entry" onChange="javascript:loadawardsdetail(this.value)">
                <option value="">&nbsp;</option>
                <?php
                  $query = "SELECT competitionid, description FROM competitiondetails WHERE 
                            currentyear=year(curdate())";
                  $result = mysql_query($query);
                  if(mysql_num_rows($result)>0)
                  {
                    while($details = mysql_fetch_array($result))
                    {                
                      echo "<option value=$details[competitionid]";
                            if($_POST['cboCompetitionID']==$details['competitionid'])
                              echo " selected=selected>$details[description]</option>";
                            else
                              echo ">$details[description]</option>";
                    }
                  }
                ?>
              </select>
              <label class="required">*</label><br class="br" />
             
              <label class="label_s">Description:</label><input type="text" name="txtDescription" size="80%" maxLength="255" class="entry" />
              <label class="required">*</label><br class="br" />
             
              <label class="label_s">&nbsp;</label><input type="submit" name="cmdSave" value="SAVE" class="buttons" />
              <br />
          </form>
          <div id="grid"></div>
    ajaxloadawards.php
    Code:
    <?php
      include("includes/connection.php");
      $query = "SELECT * FROM award WHERE competitionid='$_GET[id]'";
      $result = mysql_query($query);
      if(mysql_num_rows($result)>0)
      {
        echo "<table>";
        echo "<tr><td>Awards</td>";
        echo "<td>Status</td>";
        while($award = mysql_fetch_array($result))
        {
          echo "<tr>";
          echo "<td>$award[details]</td>";
          $query = "SELECT * FROM subcriteria WHERE awardid=$award[id]";
          $criteria = mysql_query($query);
          if(mysql_num_rows($criteria)>0)
            echo "<td>Edit Criteria</td>";
          else
            echo "<td>Create Criteria</td>";
          echo "</tr>";
        }
      }    
      echo "</table>";
    ?>
    Can you please help guys.

  2. #2
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you check my code, if I made something wrong. Please...

  3. #3
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you much, I didn't notice that.

  4. #4
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, my code already works. Thanks again.


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
  •