SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dependable select boxes problem

    Hi there....

    I have a two select boxes(project and tasks)...and when someone changes project the second select is populated with tasks with this function..

    PHP Code:
       function setOptions(selectRefoptArray) {
         if(
    selectRef!=null && optArray!=null) {
             var 
    optsRef selectRef.options;
             
    // Clear old options
       
             
    optsRef.length 0;
             
    // Insert new options
             
    for (var optArray.length-+= 2) {
                 var 
    opt = new Option(optArray[i],optArray[i+1]); // text,value
                 
    optsRef[optsRef.length] = opt;
             }
         }
       } 
    Ofcourse this method requires the project and tasks to be preloaded in array which looks like this

    project[project_id] = new Array("-----","0", "task_name", "task_id", "task2_name, "task2_id"....)

    and the HTML looks like this...

    <select name="project_id" onchange="setOptions(document.aktivnosti.elements['task_id'], project[this.options[this.selectedIndex].value]);" class="inputSel">

    and task_id select is empty because it's populated from the above array...

    <select name="task_id" class="inputSel"></select>

    so far so good....

    But the problems starts when the users needs to change some settings for one task than the project has to be selected(that's working ok) and task has to be selected....I'm setting the task like so...

    document.aktivnosti.task_id.selectedIndex = {$item->task_id};

    but as you see above the task_id select box is "empty" and this command cannot set the desired task to be selected...

    So what I get is this....when users clicks on one row the whole row is "opened" for editing....and as you see the task (NALOGA) is empty when is should be selected.....



    Any pointers would be great..TIA...
    exit(0);

  2. #2
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Huh...got it

    I changed that setOptions function and added the third parameter selectedTask....

    PHP Code:
    function setOptions(selectRefoptArrayselectedTask) {
        if(
    selectRef!=null && optArray!=null) {
            var 
    optsRef selectRef.options;
            
    // Clear old options
      
            
    optsRef.length 0;
            
    // Insert new options
            
    for (var optArray.length-+= 2) {
                var 
    opt = new Option(optArray[i],optArray[i+1]); // text,value
                     
    optsRef[optsRef.length] = opt;
                
                
    // I ADDED THIS
                
    if(selectedTask == optArray[i+1])
                    
    opt.selected true;
            }
        }
      } 
    exit(0);

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,489
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you fixed it but suggest that you check out this link

    http://www.js-examples.com/forum/viewtopic.php?t=779


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
  •