Dynamic Drop down lists
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Dynamic Drop down lists

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Dynamic Drop down lists

    Hi I'm completely new to AJAX and am trying to create a dropdown list where each field populates depending on the value entered in the previous one.

    I am trying to test it initially with just one value. My PHP works fine on Submit but AJAX won't work for me.

    The code is in an external .js file which I call along with the PHP and parameters from the main html.

    I'm a complete novece so any help would be great!

    Thanks

    I used a fairly simple tutorial and based my code on that. Here it is:

    Code:
    <form action="process.php" method="post">
    <table>
    <td align="right">Language of interest:</td>
    <td>
    <select name="language" onChange="getCity('findcity.php?language='+this.value)">
    <option value="none selected"> --- select --- </option>
    <option value="French">French</option>
    <option value="German">German</option>
    <option value="Italian">Italian</option>
    <option value="Spanish">Spanish</option>
    <option value="Russian">Russian</option>
    <tr>
    <td align="right">Course Type</td>
    <td>
    <select name="course" >
    <option value="none selected"> --- select --- </option>
    <option value="Junior">Junior</option>
    <option value="Other">Other</option>
    </tr>
    <tr>
    <td align="right">School</td>
    <td>
    <select name="school">
    <div id="citydiv">
     <option>Select School</option>
     </div>
    </tr>
    
    AJAX
    
    function getCity(strURL)
        {
    	var xmlhttp;
    if (window.XMLHttpRequest)
      {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else if (window.ActiveXObject)
      {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    else
      {
      alert("Your browser does not support XMLHTTP!");
      }
    }
         {
          req.onreadystatechange = function()
         {
          if (req.readyState == 4) { //data is retrieved from server
           if (req.status == 200) { // which represents ok status                    
             document.getElementById('citydiv').innerHTML=req.responseText;
          }
          else
          { 
             alert("There was a problem while using XMLHTTP:\n");
          }
          }            
          }        
        req.open("get", strURL, true); //open url using get method
        req.send(null);
         }
    Last edited by PeejAvery; July 14th, 2009 at 06:34 AM. Reason: Added code tags.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,877

    Re: Dynamic Drop down lists

    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2009
    Posts
    2

    Re: Dynamic Drop down lists

    Thanks

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center