Page 1 of 1

Where is the problem?

Posted: Mon Dec 05, 2011 1:58 am
by omidpand
This code does not run in line 7, why?

Code: Select all

function selectcity() 
    { 
        $('select.city').val('<?php echo($_city); ?>'); 
        $('select.c0').val('<?php echo($_data_ar[0]); ?>'); 
        c=document.forms["testForm"].elements["combo0"]; 
        change(c); 
        $('select.c1').val('<?php echo($_data_ar[1]); ?>'); 

        c=document.forms["testForm"].elements["combo1"]; 
        change(c); 
        $('select.c2').val('<?php echo($_data_ar[2]); ?>'); 

        c=document.forms["testForm"].elements["combo2"]; 
        change(c); 
        $('select.c3').val('<?php echo($_data_ar[3]); ?>'); 
    }  

The first combobox (C0) item selected and second combobox (C1) filled too, but nothing in second combobox did not select and so the third (C2) and the forth (C3) combobox did not fill.

The function change fill each combo box from what selected in previous combobx:

Code: Select all

function change(currentbox) {
   numb = currentbox.id.split("_");
   currentbox = numb[1];

    i=parseInt(currentbox)+1

// I empty all combo boxes following the current one

    while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
           (document.getElementById("combo_"+i)!=null)) {
         son = document.getElementById("combo_"+i);
        // I empty all options except the first one (it isn't allowed)
        for (m=son.options.length-1;m>0;m--) son.options[m]=null;
        // I reset the first option
        son.options[0]=new Option(displaywhenempty,valuewhenempty)
        i=i+1
    }


// now I create the string with the "base" name ("stringa"), ie. "data_1_0"
// to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill

    stringa='data'
    i=0
    while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
           (document.getElementById("combo_"+i)!=null)) {
           eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex")
           if (i==currentbox) break;
           i=i+1
    }


// filling the "son" combo (if exists)

    following=parseInt(currentbox)+1

    if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) &&
       (document.getElementById("combo_"+following)!=null)) {
       son = document.getElementById("combo_"+following);
       stringa=stringa+"_"
       i=0
       while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {

       // if there are no options, I empty the first option of the "son" combo
      // otherwise I put "-select-" in it

           if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
               if (eval("typeof("+stringa+"1)=='undefined'"))
                  eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)")
               else
                eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)")
         else
              eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)")
         i=i+1
      }
       //son.focus()
       i=1
       combostatus=''
       cstatus=stringa.split("_")
       while (cstatus[i]!=null) {
          combostatus=combostatus+cstatus[i]
          i=i+1
          }
       return combostatus;
    }
}

Re: Where is the problem?

Posted: Mon Dec 05, 2011 6:40 am
by twinedev
The problem is that didn't you already post this same problem in another thread yesterday and the answer is, but as far as the PHP Code (which is the section of the site you posted both of these messages instead of the Javascript section), the PHP code is fine assuming each of the variables you echo exist.

-Greg