2012-03-30 8 views
0

申し訳ありませんが、私は通常、このようなことを自分でやっていますが、私は制御できません。私は通常、Webスクリプト言語で働いていません(私はC++を学んでいますが、私は過去に多くのhtml経験をしていましたので、私の上司が私を仕事に就かせてくれました)しかし、私はいくつかのコードを3つのコンボボックスの入力は、htmlのjavascriptを使用します。小さなプロジェクトを完成させてaspxのページに入れるまでは、htmlと同じ方法でjsを処理しませんでしたが、私はaspxを認識しませんでした。これは小さいと思われる問題ですが、go()関数はもはや正しく動作しません。私はgo()関数にアラートボックスを入れてテストしました。アラートボックスがボタンのクリックで表示されたため、go関数がまだ呼び出されているようですが、その値をジャンプすることはできません。 3番目のコンボボックス。誰かがこのタスクを完了する他の方法についてのaspxまたは任意の提案のURLを変更するために動作する迅速な修正を知っていますか?どんな助力も大変ありがとうございます。ありがとうございました。JSがaspxからhtmlに変更されました

<script language="JavaScript" type="text/javascript"> 

// first combo box 

data_1 = new Option("Acura", "$"); 

// second combo box 

data_1_1 = new Option("MDX", "-"); 

// third combo box 

data_1_1_1 = new Option("2007", "http://www.DawnEnterprises.co/2007-Acura-MDX-Accessories.aspx"); 


displaywhenempty="" 
valuewhenempty=-1 

displaywhennotempty="-select-" 
valuewhennotempty=0 


function change(currentbox) { 
numb = currentbox.id.split("_"); 
currentbox = numb[1]; 

i=parseInt(currentbox)+1 


while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) && 
     (document.getElementById("combo_"+i)!=null)) { 
    son = document.getElementById("combo_"+i); 

for (m=son.options.length-1;m>0;m--) son.options[m]=null; 

son.options[0]=new Option(displaywhenempty,valuewhenempty) 
i=i+1 
} 

stringa='data' 
i=0 
while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) && 
     (document.getElementById("combo_"+i)!=null)) { 
      eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex") 
     if (i==currentbox) break; 
     i=i+1 
} 

following=parseInt(currentbox)+1 

if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) && 
    (document.getElementById("combo_"+following)!=null)) { 
    son = document.getElementById("combo_"+following); 
    stringa=stringa+"_" 
    i=0 
    while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) { 


if ((i==0) && eval("typeof("+stringa+"0)=='undefined'")) 
    if (eval("typeof("+stringa+"1)=='undefined'")) 
     eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)") 
    else 
     eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)") 
else 
      eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)") 
i=i+1 
} 
    //son.focus() 
    i=1 
    combostatus='' 
    cstatus=stringa.split("_") 
    while (cstatus[i]!=null) { 
     combostatus=combostatus+cstatus[i] 
     i=i+1 
     } 
    return combostatus; 
} 
} 
function go(the_value) { 
location = 
document.MMYSearch.combo2. 
options[document.MMYSearch.combo2.selectedIndex].value 
} 
</script> 

     <form id="MMYSearch" action="../../../js/MMYSearch.js" name="MMYSearch"> 
      <h4>Vehicle <span class="selection">Selection</span></h4> 
      <p>Select the Make of your vehicle:</p> 
      <select name="combo0" id="combo_0" onchange="change(this);" style="width:230px;"> 
       <option value="value1">-select-</option> 
       <option value="value2">Acura</option> 

      </select> 
      <p>Select the Model of your vehicle:</p> 
      <select name="combo2" id="combo_1" onchange="change(this);" style="width:230px;"> 
      </select> 
      <p>Select the Year of your vehicle:</p> 
      <select name="combo2" id="combo_2" onchange="change(this);" style="width:230px;"> 
      </select> 
      <div> 
       <input type="button" name="Select" value="Select" onclick="go()" /> 
      </div> 
     </form> 
+0

あなたの 'go()'は何をすべきでしょうか?今のところ、 'location =" something "は私にはあまり意味がありません: –

+0

あなたの奇妙なコードがevalとstrang type checkでいっぱいですが、それらを削除できますか? –

+0

そのevalはまったく必要ありません。 ifをtypeof(document.getElementById( "combo _" + i))!= "undefined"に置き換えることができます。 – jrummell

答えて

1

私はブラウザを3番目のドロップダウンでURLにリダイレクトしようとしていると思います。あなたの "行く()" 関数の中で、私は、これはあなたが求めて何を得るだろうと思い

window.location.href = 

location = 

を交換してください。

少し建設的なアドバイス:あなたのコードが読みやすくなっていれば、人々はもっとあなたを助けることができます。私はあなたがあなたの経営陣によってこれに押し込まれたことを理解しています。あなたはあなたがC++のバックグラウンドから来ていると言ったので、私はあなたを責めません。変数をもっと意味のある名前にしてくれれば、私たち(そしてあなたも含めてコードを管理しなければならない人)はもっと簡単になります。 "data_1"、 "data_1_1"、 "son"、 "go()"のような名前は、どのコードを実行すべきかを理解するのをより困難にします。あなたは "goToVehiclePage()"のような名前を試してみるかもしれません。

+0

ええ、それは命名規則のためのより多くの時間と概念的なものだったことに同意します。私は約6年間何のjsもしなかった。 – Rob

+0

あなたが近くにありがとう。私の問題は、top.location.href!誰も助けてくれてありがとう! – Rob

+0

JSで注意する必要があることは、予約語や既知のオブジェクトではない単語を入力すると暗黙的に変数になります。この場合は "location"になります何もしないコード。 – SouthShoreAK

関連する問題