2013-06-05 70 views
0

我想要一個變量等於一個下拉的選項標記的值,但它的返回未定義。它應該採取每個選項的價值,並將其設置爲data2,但事實並非如此。任何幫助將不勝感激。爲什麼我的下拉菜單值未定義?

function opis(dat1, dat2) { 
     var data1 = dat1; 
     var data2 = dat2; 
     this.getdata1 = function() { 
      return data1; 
     }; 
     this.getdata2 = function() { 
      return data2; 
     }; 
     this.setData2 = function (x) { 
      data2=x; 
     }; 
    } 
    var opis_r2 = new opis("", ""); 
    var opis_r3 = new opis("", ""); 
    var opis_r4 = new opis("", ""); 
    var opis_r5 = new opis("", "????"); 
    var opis_r6 = new opis("", ""); 
    var opis_r7 = new opis("", ""); 
    function check_gen() { 
     alert("check_gen"); 
     opis_r2.setData2(document.forms['mil_resistors_gen'].R22.value); 
     opis_r3.setData2(document.forms['mil_resistors_gen'].R33.value); 
     opis_r4.setData2(document.forms['mil_resistors_gen'].R44.value); 
    opis_r6.setData2(document.forms['mil_resistors_gen'].R66.value); 
     opis_r7.setData2(document.forms['mil_resistors_gen'].R22.value); 
     explain_gen(); 
    } 

    //============================================== 

    function resistance_gen(x) { 
     var y, z; 
     var ciag = ""; 
     var zera = 0; 
     var txt1 = ""; 

     y = x.value; 

     if (check_coma_gen(y) !== 0) { 
      opis_r5.data2 = check_coma_gen(y); 
     } else { 
      if (check_0_position_gen(y) > 0) { 
       window.alert("Incorrect data, enter correct value"); 
       opis_r5.data2 = "????"; 
       document.forms['mil_resistors_gen'].R55.focus(); 
      } else { 
       zera = ile_zer_gen(y); 
       ciag = first_3d_gen(y, zera); //500 
       zera = y.length - ciag.length; 
       opis_r5.data2 = ciag + zera; 

      } 
     } 
     explain_gen(); 
    } 
    //============================================ 

    function check_coma_gen(x) { 
     var y, z, c, d, e, dl, f; 

     y = x; 
     c = 0; 
     d = 0; 

     dl = x.length; 
     while (c < dl) { 
      if (x.charAt(c) == ".") { 
       d = 1; 
      } 
      if (x.charAt(c) != ".") { 
       d = d; 
      } 
      c++; 
     } 

     if (d > 0) { 
      z = y.replace('.', 'R'); //zamienia . na R 
      e = z.indexOf('R', [0]); //podaje na ktorej poz jest R 
      if (e > 2) { 
       window.alert("Incorrect data, enter correct value"); 
      } else { 
       f = z.slice(0, e + 2); //wycina ciag od 0 do poz d-1 
       return (f); 
      } 
     } 
     if (d === 0) { 
      return (0); 
     } 
    } 
    //============================================ 

    function check_0_position_gen(x) { 
     var dl, c, d; 

     c = 3; 
     d = 0; 
     dl = x.length; 
     while (c < dl) { 
      if (x.charAt(c) === 0) { 
       d = d; 
      } 
      if (x.charAt(c) !== 0) { 
       d = 1; 
      } 
      c++; 
     } 
     return (d); 
    } 
    //============================================ 

    function first_3d_gen(a, b) { 
     var dl, c; 

     c = 0; 
     dl = a.length; 
     c = a.slice(0, dl - b); 
     if (c.length == 1) { 
      c = c + "00"; 
     } 
     if (c.length == 2) { 
      c = c + "0"; 
     } 
     //window.alert(c); 
     return (c); 
    } 
    //============================================ 

    function ile_zer_gen(x) { 
     var dl, c, straznik; 

     c = 0; 
     straznik = 0; 
     dl = x.length; 

     //window.alert("dlugosc: "+dl); 

     while (dl > 0) { 
      if (x.charAt(dl - 1) === 0) { 
       c++; 
      } 
      if (x.charAt(dl - 1) !== 0) { 
       straznik = 1; 
      } 
      if (straznik == 1) { 
       dl = 0; 
      } 
      dl--; 
     } 
     //window.alert("liczba 0: "+c); 
     return (c); 
    } 
    //============================================ 


    function explain_gen() { 
     var part_nr = ""; 
     part_nr_gen = "Part number is: RN" + opis_r2.getData2 + opis_r3.getData2 + opis_r4.getData2 + opis_r5.getData2 + opis_r6.getData2 + opis_r7.getData2; 
     document.forms['mil_resistors_gen'].T33.value = part_nr_gen; 
    } 
+3

不能只發布相關的代碼嗎?需要一段時間才能讀取所有代碼,以檢測問題的來源:) –

回答

0

你有opis_r2.getData2,但是屬性getdata2(無上限)。也是它的一個功能,所以你最終需要()

part_nr_gen = "Part number is: RN" + opis_r2.getdata2() + opis_r3.getdata2() + 
    opis_r4.getdata2() + opis_r5.getdata2() + opis_r6.getdata2() + opis_r7.getdata2(); 
相關問題