Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Linked drop boxes

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Linked drop boxes

Postby border20 » Mon Feb 17, 2003 12:45 pm

I have two drop boxes that need to be linked... the content of the second depends on the value of the first,,, how would i do this ? [/img]
border20
New php-forum User
New php-forum User
 
Posts: 32
Joined: Tue Jan 28, 2003 10:19 am
Location: Québec

Postby Redcircle » Mon Feb 17, 2003 1:22 pm

Code: Select all
<script language="JavaScript">
function check_private()
{
if(change_permissions.private.checked == true)
{
change_permissions.users.disabled = false
change_permissions.elements['has_access[]'].disabled = false
change_permissions.add.disabled = false
change_permissions.remove.disabled = false

}
else
{
change_permissions.users.disabled = true
change_permissions.elements['has_access[]'].disabled = true
change_permissions.add.disabled = true
change_permissions.remove.disabled = true

}
}
function goodcheck(fbox)  {
     for(var i=0; i<fbox.options.length; i++)  {
          if(fbox.options[i].selected
                    && fbox.options[i].value == "0") {
               fbox.options[i].selected=false;
               return false;
          }
      }
     return true;
}

function move(fbox,tbox,owner) {
     for(var i=0; i<fbox.options.length; i++) {
          if(fbox.options[i].selected && fbox.options[i].value != "" && fbox.options[i].value != owner) {
               var no = new Option();
               no.value = fbox.options[i].value;
               no.text = fbox.options[i].text;
               tbox.options[tbox.options.length] = no;
               fbox.options[i].value = "";
               fbox.options[i].text = "";
               fbox.options[i].selected=false;
               //tbox.options[tbox.options.length-1].selected=true;
          }
     }
     BumpUp(fbox);
     SortD(tbox);
     if(fbox.length > 0)
    {
    fbox.options[0].selected=true;
    fbox.disabled = false;
    }
   
   
}

function BumpUp(box)  {
     for(var i=0; i<box.options.length; i++) {
          if(box.options[i].value == "")  {
               for(var j=i; j<box.options.length-1; j++)  {
                    box.options[j].value = box.options[j+1].value;
                    box.options[j].text = box.options[j+1].text;
               }
               var ln = i;
               break;
          }
     }
     if(ln < box.options.length)  {
          box.options.length -= 1;
          BumpUp(box);
     }
}

function SortD(box)  {
     var temptxt = '';
     var tempval = '';
     var tempsel = false;

     for(var x=0; x < box.options.length-1; x++)  {
          for(var y=(x+1); y < box.options.length; y++)  {
               if(box.options[x].text > box.options[y].text)  {
                    temptxt = box.options[x].text;
                    tempval = box.options[x].value;
                    tempsel = box.options[x].selected;

                    box.options[x].text = box.options[y].text;
                    box.options[x].value = box.options[y].value;
                    box.options[x].selected = box.options[y].selected;

                    box.options[y].text = temptxt;
                    box.options[y].value = tempval;
                    box.options[y].selected = tempsel;
               }
          }
     }
}
function select_all(box)
{
sellength = box.length;
for(x=0; x<sellength; x++)
box.options[x].selected = true;
}


There's the javascript

Code: Select all
if (goodcheck(this.form.users)) move(this.form.users,this.form.elements['has_access[]'])


Put that in any button.

Variable names may differ. this is not a working model but should give you some idea.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.