SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help regarding dynamic fields + AJAX

    Hi,

    I am new to AJAX. I have a MySQL database with list of categories and subcategories. I have created a table where the first column contains the list pf categories and the second column calls the subcategories from an external php page called subcats where i echo the subcats.

    I used xmlhttp.open for the <div id="getsubcats"> this is the second column.

    I have a form below the table. I want to change the form fields ased on subcat selection. How do i do that?

    Thanks.

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    post your code so we can see what is going on.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my code :

    Code HTML4Strict:
    <html>
    <head>
    <script type="text/javascript">
    function showUser(str)
    {
    if (str=="")
      {
      document.getElementById("txtHint").innerHTML="";
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","getuser1.php?q="+str,true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>
    <table> <tr> <td>
    <form>
    <select name="users" onchange="showUser(this.value)" size="9">
    <option value="">Select a person</option>
    <option value="1">Name1</option>
    <option value="2">Name2</option>
    <option value="3">Name3</option>
    <option value="4">Name4</option>
    <option value="5">Name5</option>
    <option value="6">Name6</option>
    <option value="7">Name7</option>
     
    </select>
    </form>  </td> <td valign="top">
    <div id="txtHint"><b>Person info will be listed here.</b></div>
    </td> </tr> </table>


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
  •