複数のプルダウンメニューを使ってページリンクをさせています。
その際ページリンクと同時に、他のメニューの選択項目を初期値す方法を教えてください。
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まで同様)
です。
どうぞよろしくお願いいたします。
No.2ベストアンサー
- 回答日時:
下記間違いです。
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);
}
いずれにせよ、テスト未です。
保障はしません・・・。すいません。
Mizyuさん、回答ありがとうございました。
うまくいきました!
大変勉強になりました。
ありがとうございました。
※これを参考にされる方は、
function LInitの中の最後の行のLISTをListにしてお使いくださいね。
No.3
- 回答日時:
だって、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さんに教えていただいた方法にしましたが、大変参考になりました。
ありがとうございました。
またわからないことがあったら、よろしくお願いします。
No.1
- 回答日時:
自信はまったくないのですが・・・。
> 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);
}
このようにすればいいように思えます。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・14歳の自分に衝撃の事実を告げてください
- ・架空の映画のネタバレレビュー
- ・「お昼の放送」の思い出
- ・昨日見た夢を教えて下さい
- ・ちょっと先の未来クイズ第4問
- ・【大喜利】【投稿~10/21(月)】買ったばかりの自転車を分解してひと言
- ・メモのコツを教えてください!
- ・CDの保有枚数を教えてください
- ・ホテルを選ぶとき、これだけは譲れない条件TOP3は?
- ・家・車以外で、人生で一番奮発した買い物
- ・人生最悪の忘れ物
- ・【コナン30周年】嘘でしょ!?と思った○○周年を教えて【ハルヒ20周年】
- ・ハマっている「お菓子」を教えて!
- ・最近、いつ泣きましたか?
- ・夏が終わったと感じる瞬間って、どんな時?
- ・10秒目をつむったら…
- ・人生のプチ美学を教えてください!!
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・都道府県穴埋めゲーム
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
クリッカブルマップのリンク部...
-
Javascriptで定期的にF5を押す...
-
Latexに関する質問です。
-
TexでΣの添え字の位置直し
-
ラジオボタンでreadonlyの切替え
-
if(document.all && navigator....
-
responseTextについて
-
javascriptの基本的なことだと...
-
VBAでIE操作
-
VBAからIEの操作
-
onchangeでロケーションジャン...
-
C#OpenCv V4にのエラーに関する...
-
google apps scriptの終了のさせ方
-
同じIDで定義した要素の配列を...
-
二次元配列を使って順位をだす...
-
idを使わずにonclickで自身の要...
-
翌月を取得するGASが分かりません
-
getElementByIdを使用したグロ...
-
ActiveXobjectが作成できない
-
Excel VBA の ChangeFileAccess
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
javascriptの基本的なことだと...
-
Latexに関する質問です。
-
DOM要素を削除しても、イベント...
-
Null またはオブジェクトではあ...
-
JavaScript window.openで開く...
-
onload時にPostBackを発生させ...
-
XMLでのAttributeを持ったNode...
-
FireFoxのjavascriptで自動でキ...
-
showModalDialogで開いた画面を...
-
時間でlink, vlink, alinkの文...
-
TexでΣの添え字の位置直し
-
デフォルトのリンクの色
-
webページ上のTabキーの動き
-
iframeのソースを取得したい
-
乗換案内 VBAで操作したい
-
質問です! Operaって、document...
-
ラジオボタンをクリックしたい
-
クリッカブルマップのリンク部...
-
文字を一文字ずつ表示
-
document.getElementsByClass
おすすめ情報