2017-03-27 16 views
0

Function1は、function1の最後にパラメータshowCyclists(country.id)を使用してshowCyclists()を呼び出します。これにより、showCylists関数が起動されます。JS変数をパラメータとして使用してJS変数を呼び出す

function showCyclists(countryID){ //creates a table with athlete of country 
     function cyclistOrder() { //checks on change select box and appends to sort 
      sql="SELECT name, ISO_id, height, weight, gender FROM `Cyclist`"; //get info from cyclist db 

      select = document.getElementById("selectCycle") 

      if(select.value == "height"){ 
       sql += " ORDER BY height "; 
      } 

      return sql; 
     } 
//continue with showCyclists() 

この機能を実行するには、選択ボックスの変更時に同じパラメータ(国ID)を使用する必要があります。

明らかに私は<select id="selectCycle" class="select-cycle" onchange="showCyclists()">を実行できません。なぜなら、パラメータなしで私の関数を呼び出すからです。

どうすればこの問題を解決できますか? ありがとうございます

+0

'onchange =" showCyclists(value) "' – dandavis

+0

これはうまくいきません。関数1で取得した国IDでなければならないときは、パラメーター値として関数を呼び出します。 – Pete

+0

'function1'は表示されませんが、他のものをラップすると、クロージャを使用してパラメータに到達することができます。 – dandavis

答えて

1

onchange="showCyclists()onchange="showCyclists(this)に変更すると、必要なパラメータには機能内でthis.options[this.selectedIndex].valueがアクセスしています。各selectオプションの値宣言に正しいcountryIDを入れる必要があります。

+0

に '.target'がありませんか? – dandavis

+0

何を意味するのですか? – Pete

+0

'e'は' this'のタイプミスです – GavinBrelstaff

関連する問題