Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Drop Down List

  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Drop Down List

    I've managed to populate two drop down lists using a combo of Ajax and Php.
    My only problem is however that I can't pass variables between the scripts.

    Although the first one works fine the one below executes but no values are brought back.

    For instance I would like whichever choice for city to effect the field below it, but can only do this by manually specifiying a particular city in the SQL query.

    Could anyone tell me what parameters I need to specify in order to pass variables accross?

    Here's some of my code. Any help would be great cause I'm pretty lost.

    Thanks

    findlevel.php

    Code:
    <?php
    
    $language = $_GET["language"];
    $school = $_GET['school'];
    
    mysql_connect("localhost", "root", "filabo01") or die(mysql_error());
      
      mysql_select_db("burkes1_jos") or die(mysql_error());
    
      
    
    $query = mysql_query("select le.leveltype from ssa_level as le, ssa_schoolid as s, ssa_lang as l, ssa_course as c
     where s.school = '$school'
     and s.schoolid = c.schoolid
     and c.schoolid = c.levelid
     group by le.leveltype")
    or die (mysql_error()); 
    
    ?>
    
    <select name ="level" onChange="getDuration(this.value)">
    <option>Select Level</option>
    <? while($row = mysql_fetch_array($query)) { ?>
       <option value><?=$row['leveltype']?></option>
    <? } 
    ?>
    </select>
    getschool.js

    Code:
    function getDuration(school)
    {
    {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    var url="getduration.php";
    url=url+"?school="+school;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    }
    
    function stateChanged()
    {
    if (xmlhttp.readyState==4)
    {
    document.getElementById("durationdiv").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;
    }
    }
    
    function getLevel(school)
    {
    {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    var url="findlevel.php";
    url=url+"?school="+school;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    }
    
    function stateChanged()
    {
    if (xmlhttp.readyState==4)
    {
    document.getElementById("leveldiv").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;
    }
    }
    
    function getSchool1(langid)
    {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    var url="findcity.php";
    url=url+"?language="+langid;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    }
    
    function stateChanged()
    {
    if (xmlhttp.readyState==4)
    {
    document.getElementById("schooldiv").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;
    }
    Last edited by daved83; 07-22-2009 at 01:10 PM. Reason: add code tags

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Please edit your post to use code tags so it is readable.

    What do you mean pass variables across?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Eric,

    Thanks for the repy. What I mean is get the variables after the are passed into the URL?? Does this make sense? Sorry I'm new to this. I think the following lines should achieve this and work for my first dropdown.

    findcity.php

    Code:
    <select name="school" onChange="getLevel(this.value)";>
    getschool.js

    Code:
    var url="findlevel.php";
    url=url+"?school="+school;
    url=url+"&sid="+Math.random();
    For some reason when I declare the variable in another PHP file it isn't recognised. Excuse my inexperience sorry. Once again any help greatly appreciated.


  •  

    Posting Permissions

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