SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change of drop down value after first drop down selection not working

    I have a bit of code and basically I cant get it to work.

    The idea is a country, region thing which has been many times, but for some reason, when I choose the country the region drop down acknowledges the selction has been made but only 'Anywhere' rather than the value, and no values appear.

    Then when I come into the page having already selected a hotel, the country works well, the correct region values for the country show up, but it stays on the first one, rather than jumping to the correct value.

    Hopefully someone can spot the problem, and help me out.

    Code:
    var country = new Array();
    var region = new Array();
    var countryregion = new Array();
    function fillregion(countryid)
    {
       
    var i=0;
    document.form1.selregion.options.length=0;
    for(j=0;j<=countryregion.length;j++)
    {   
    if(countryregion[j]==countryid)
    {
    /*document.form1.selregion.options[i] = new Option()*/
    document.form1.selregion.options[i] = new Option(region[j],j)
    document.form1.selregion.options[i].value=j;
    document.form1.selregion.options[i].innerText=region[j];
    i++;
    }
    }
     
    if(countryid==0 || i==0 )
    {
    document.form1.selregion.options[0] = new Option()
    document.form1.selregion.options[0].value=0;
    document.form1.selregion.options[0].innerText="Anywhere";
    }
    }
    
    
         <select name="selcountry" size="1" onChange="fillregion(this.value);">
         <?php $qw=mysql_query("select * from tbl_countries order by Nom_Cntry") or die (mysql_error());
         while($r=mysql_fetch_assoc($qw))
         { 
          if($r['Id_Cntry']==$hotcntry)
          {
           echo "<option value='$r[Id_Cntry]' selected>$r[Nom_Cntry]</option>";
          }
          else
          {
           echo "<option value='$r[Id_Cntry]'>$r[Nom_Cntry]</option>";
          }
           } ?>
         </select>
    
    <select name="selregion" size="1">
         <?
          $qu=mysql_query("select * from tbl_resorts where IdCntry_Rsrt=$hotcntry"); // or die (mysql_error());
          while($r=mysql_fetch_assoc($qu))
          {      
           if($r['Id_Rsrt']==$regioncmb)
           {
           echo "<option name=$r[1] selected>$r[Nom_Rsrt]</option>";
           }
           else
           {
           echo "<option name=$r[1]>$r[Nom_Rsrt]</option>";       
           }
          }
          
          
         ?>
           </select>

  2. #2
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have the second part of that problem sorted now, the problem I have got now is that when a country is choosen the regions dont get pulled from the database, and all I get is the 'Anywhere' option so that at least shows that the function is working to read when the country has been selected.


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
  •