dポイントプレゼントキャンペーン実施中!

複数のプルダウンメニューを使ってページリンクをさせています。
その際ページリンクと同時に、他のメニューの選択項目を初期値す方法を教えてください。

No.157334で同じような質問があったので、それを参考に以下のように記述してみましたが、

function reSel(c) {
for(i=0; i<9; i++){
var s="document.unit.DDList";
var x=s+i;
if(x != c){
x.selectedIndex=0; //ココがうまくいきません。
}
}
}
function Li_0(obj){
parent.res.location.href=obj.options[obj.selectedIndex].value;
reSel("document.unit.DDList0");
}
(以降 Li_8まで同様)

<form name="unit" method="post">
<select name="DDList0" size="1" onChange="Li_0(this)">
<option value="help.html" selected> </option>
<option value="unit_a.html">AAA</option>
<option value="unit_b.html">BBB</option>
</select>
(以降 DDList8まで同様)

です。
どうぞよろしくお願いいたします。

A 回答 (3件)

下記間違いです。




function reSel(objc) {

LInit(objc,document.unit.DDList0);
LInit(objc,document.unit.DDList1);
LInit(objc,document.unit.DDList2);
LInit(objc,document.unit.DDList3);
LInit(objc,document.unit.DDList4);
LInit(objc,document.unit.DDList5);
LInit(objc,document.unit.DDList6);
LInit(objc,document.unit.DDList7);
LInit(objc,document.unit.DDList8);

}

function LInit(objc , List){
if ( objc! = List ){
LIST.selectedIndex = 0;
}

function Li_0(obj){
parent.res.location.href=obj.options[obj.selectedIndex].value;
reSel(obj);
}

いずれにせよ、テスト未です。
保障はしません・・・。すいません。
    • good
    • 0
この回答へのお礼

Mizyuさん、回答ありがとうございました。
うまくいきました!
大変勉強になりました。
ありがとうございました。

※これを参考にされる方は、
function LInitの中の最後の行のLISTをListにしてお使いくださいね。

お礼日時:2002/05/31 18:57

だって、x は文字列じゃん。

文字列には、selectedIndex なんてプロパティは
存在しませんから、期待通りに動かないのは当たり前です。

試してないけど、こんな感じかなあ?

function reSel(c) {
 for (i = 0 ; i < document.unit.length ; ++i) {
  if (document.unit.elements[i].name != c) {
   document.unit.elements[i].selectedIndex = 0
  }
 }
}

function Li_0(obj) {
 ...
 reSel("DDList0")
}

# select 以外の要素が form に入っていると、もう一工夫必要です

この回答への補足

回答ありがとうございました。
おっしゃるとおりでした。

上記の方法でやってみますとDDList0の選択項目も0になってしまいましたので、
今回はMizyuさんに教えていただいた方法にしましたが、大変参考になりました。
ありがとうございました。

またわからないことがあったら、よろしくお願いします。

補足日時:2002/05/31 19:02
    • good
    • 0

自信はまったくないのですが・・・。



> var s="document.unit.DDList";
> var x=s+i;
この表記で変数xに入るのは文字列ではないでしょうか?
それともJavaScriptで文字列を変数(オブジェクト変数)化する処理が入っているのであれば、話は別ですが。

連続表記するのはめんどくさいかもしれませんが

function reSel(objc) {

LInit(c,document.unit.DDList0);
LInit(c,document.unit.DDList1);
LInit(c,document.unit.DDList2);
LInit(c,document.unit.DDList3);
LInit(c,document.unit.DDList4);
LInit(c,document.unit.DDList5);
LInit(c,document.unit.DDList6);
LInit(c,document.unit.DDList7);
LInit(c,document.unit.DDList8);

}

function LInit(objc , List){
if ( objc! = List ){
LIST.selectedIndex = 0;
}

function Li_0(obj){
parent.res.location.href=obj.options[obj.selectedIndex].value;
reSel(obj);
}

このようにすればいいように思えます。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!