我试图让一个变量等于下拉选项标签的值,但它返回未定义。它应该获取每个选项的值并将其设置为 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;
}