私は、ユーザーが入力しなければならない16個の要素があるフォームを持っています。これらの要素のドロップダウンには0〜16の値があります。これらすべての要素の初期値はゼロです。javascriptのドロップダウンリストの値を変更する
ユーザーは各要素に対して1から16までの値を選択できますが、各要素は1回だけ 要素を選択することができます。彼らはそれぞれの値を選択するので、私は選択された値を排除するためにすべての要素のドロップダウンの値を変更しています。最後に、各ドロップダウンに残っている唯一の値は0で、ユーザーがそのドロップダウンで選択した値です。また、ユーザーが値をゼロに戻した場合は値を戻します。
私はChromeとFireFoxでうまく動作しますが、IEでは失敗します。問題はopts.options
が定義されていないエラーであることです。何とかIE以外のすべてのブラウザで動作します。私はドロップダウンに値を設定するメソッドにオブジェクトとして要素を渡す必要があると思う。ここで
は、それはまた、ドロップダウンを初期化するために、負荷に メソッドを呼び出し、メソッドはPHP/HTMLで呼ばれる方法である:ここでは
echo "<TD bgcolor=$color width=15><SELECT name='$pts' onChange='populatePoints(this)' </SELECT></TD>n";
は、関連するJSです:
function populatePoints(x){
setOptions (document.form1.G1_Points)
setOptions (document.form1.G2_Points)
setOptions (document.form1.G3_Points)
setOptions (document.form1.G4_Points)
setOptions (document.form1.G5_Points)
setOptions (document.form1.G6_Points)
setOptions (document.form1.G7_Points)
setOptions (document.form1.G8_Points)
setOptions (document.form1.G9_Points)
setOptions (document.form1.G10_Points)
setOptions (document.form1.G11_Points)
setOptions (document.form1.G12_Points)
setOptions (document.form1.G13_Points)
setOptions (document.form1.G14_Points)
setOptions (document.form1.G15_Points)
setOptions (document.form1.G16_Points)
}
function setOptions (opts){
pointValue = opts.value
opts.options.length = 0
var x = 0
opts.options[x] = new Option(0)
x++
for (i=1;i<17;i++) {
if (document.form1.G1_Points.value != i &&
document.form1.G2_Points.value != i &&
document.form1.G3_Points.value != i &&
document.form1.G4_Points.value != i &&
document.form1.G5_Points.value != i &&
document.form1.G6_Points.value != i &&
document.form1.G7_Points.value != i &&
document.form1.G8_Points.value != i &&
document.form1.G9_Points.value != i &&
document.form1.G10_Points.value != i &&
document.form1.G11_Points.value != i &&
document.form1.G12_Points.value != i &&
document.form1.G13_Points.value != i &&
document.form1.G14_Points.value != i &&
document.form1.G16_Points.value != i &&
document.form1.G15_Points.value != i){
opts.options[x] = new Option(i)
x++}}
opts.value = pointValue
}
は、なぜあなたはこれをしたいですか?それは忙しい仕事のようです... – Endophage
あなたはあなたのフォームにアクセスすることができますすべてのコピーペーストを行うのではなく、 'document '[form' + form_number] ['G' + i + '_ Points']。 – hugomg