No.157334でleaz024さんに「複数プルダウンメニュー」について教えてもらったものですが、ひとつ、追加したいことがあるので教えてください。
教えていただいたスクリプトは
<script language="javascript">
<!--
function A_Li() {
Sel=document.Link1.OP.selectedIndex;
Ms=document.Link1.OP.options[Sel].value;
parent.main.location.href=Ms;}
function B_Li() {
Sel=document.Link1.OP2.selectedIndex;
Ms=document.Link1.OP2.options[Sel].value;
parent.main.location.href=Ms;}
// -->
</script>
<FORM name="Link1">
<SELECT name="OP" onChange="A_Li()" size="1">
<OPTION Value="main.htm" SELECTED>ページを選んでください
<option value="main.htm">ぺージ1</option>
<OPTION Value="abc.htm">ページ2
<OPTION Value="def.htm">ページ3
</SELECT>
<SELECT name="OP2" onChange="B_Li()" size="1">
<OPTION Value="aaa.htm" SELECTED>ページを選んでください
<option value="bbb.htm">ぺージ1</option>
<OPTION Value="ccc.htm">ページ2
<OPTION Value="ddd.htm">ページ3
</SELECT>
です。
例えば
OP2のメニューをクリックしたあと
OP3のメニューをクリックしたときにOP2のメニューが初期の
表示メニューに戻したいのですが、どう変えればよいでしょうか。
初心者なので本を見てみたのですがわかりませんでした。
どうぞよろしくお願いいたします。
No.2ベストアンサー
- 回答日時:
こんにちはshizukuさん、xruzです、やはりはずしていましたね(=.=;
<script language="javascript">
<!--
// ここから追加
var s;
function reSel(c) {
if(s&&(s!=c)) s.options[0].selected=true;
s=c;
}
// ここまで追加
function A_Li() {
Sel=document.Link1.OP.selectedIndex;
Ms=document.Link1.OP.options[Sel].value;
parent.main.location.href=Ms;
reSel(document.Link1.OP); // 追加
}
function B_Li() {
Sel=document.Link1.OP2.selectedIndex;
Ms=document.Link1.OP2.options[Sel].value;
parent.main.location.href=Ms;
reSel(document.Link1.OP2); // 追加
}
function C_Li() {
Sel=document.Link1.OP3.selectedIndex;
Ms=document.Link1.OP3.options[Sel].value;
parent.main.location.href=Ms;
reSel(document.Link1.OP3); // 追加
}
function D_Li() {
Sel=document.Link1.OP4.selectedIndex;
Ms=document.Link1.OP4.options[Sel].value;
parent.main.location.href=Ms;
reSel(document.Link1.OP4); // 追加
}
function E_Li() {
Sel=document.Link1.OP5.selectedIndex;
Ms=document.Link1.OP5.options[Sel].value;
parent.main.location.href=Ms;
reSel(document.Link1.OP5); // 追加
}
function F_Li() {
Sel=document.Link1.OP6.selectedIndex;
Ms=document.Link1.OP6.options[Sel].value;
parent.main.location.href=Ms;
reSel(document.Link1.OP6); // 追加
}
こんな感じでいかがでしょうか? 同じ処理になるよう共通化しました。
注)全部を貼り付けても動きません。追加のところだけ張付けてくださいね。
No.1
- 回答日時:
こんにちはshizukuさん、xruzです。
初期の表示メニューへ戻すわけではありませんが指定したoptionsを
表示するようにするには以下のように一行追加してください。
(はずしてますでしょうか?)
function B_Li() {
Sel=document.Link1.OP2.selectedIndex;
Ms=document.Link1.OP2.options[Sel].value;
parent.main.location.href=Ms;
document.Link1.OP.options[0].selected=true; // この行を追加しました。
}
がんばってくださいね。
この回答への補足
早速のご回答をありがとうございます!
おかげさまでAとBは動かすことができました。
ただ、、、
3つめ(function C)からの記述がどう応用したらよいかわかりません。
どのメニューをクリックしてもすべて(直前にクリックした表示)を初期値に戻すことができますか?
本当にお手数ですが、教えてください。。
<script language="javascript">
<!--
function A_Li() {
Sel=document.Link1.OP.selectedIndex;
Ms=document.Link1.OP.options[Sel].value;
parent.main.location.href=Ms;
document.Link1.OP2.options[0].selected=true;}
function B_Li() {
Sel=document.Link1.OP2.selectedIndex;
Ms=document.Link1.OP2.options[Sel].value;
parent.main.location.href=Ms;
document.Link1.OP.options[0].selected=true;}
function C_Li() {
Sel=document.Link1.OP3.selectedIndex;
Ms=document.Link1.OP3.options[Sel].value;
parent.main.location.href=Ms;}
function D_Li() {
Sel=document.Link1.OP4.selectedIndex;
Ms=document.Link1.OP4.options[Sel].value;
parent.main.location.href=Ms;}
function E_Li() {
Sel=document.Link1.OP5.selectedIndex;
Ms=document.Link1.OP5.options[Sel].value;
parent.main.location.href=Ms;}
function F_Li() {
Sel=document.Link1.OP6.selectedIndex;
Ms=document.Link1.OP6.options[Sel].value;
parent.main.location.href=Ms;}
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
DOM要素を削除しても、イベント...
-
選択肢によってラジオボタンを...
-
javascriptの基本的なことだと...
-
ネスケ6以上でも動作させたいの...
-
質問です! Operaって、document...
-
Null またはオブジェクトではあ...
-
[DOM] 取得したHTMLのオブジェ...
-
responseTextのデータをevaluate
-
デフォルトのリンクの色
-
二つのフィルタを同時に使用したい
-
onClickイベントの変更方法
-
FireFoxのjavascriptで自動でキ...
-
onload時にPostBackを発生させ...
-
関数でy=g(x)のgとは何の略です...
-
同じIDで定義した要素の配列を...
-
ASP.NETのコントロールの値をJa...
-
ASP+アクセスでのSQLコメントに...
-
javascriptを用いて作成された...
-
C#OpenCv V4にのエラーに関する...
-
<a>タグのテキストを取得
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
javascriptの基本的なことだと...
-
Latexに関する質問です。
-
DOM要素を削除しても、イベント...
-
文字を一文字ずつ表示
-
Null またはオブジェクトではあ...
-
excle VBA とweb上の検索を利用...
-
JavaScript window.openで開く...
-
FireFoxのjavascriptで自動でキ...
-
UWSCでオンクリックのボタンを...
-
ラジオボタンでreadonlyの切替え
-
XMLでのAttributeを持ったNode...
-
乗換案内 VBAで操作したい
-
Javascriptで定期的にF5を押す...
-
responseTextについて
-
webページ上のTabキーの動き
-
クリッカブルマップのリンク部...
-
ie操作 フレームのURLが...
-
TexでΣの添え字の位置直し
-
連動するセレクトボックスの内...
-
LaTeX:数式を等号揃えにする方法
おすすめ情報