2012-02-13 22 views
0

こんにちは、ありがとうございました。私はこれに新しいので、おそらく私は問題を把握できない理由を説明することに注意してください。他の入力に基づいて入力フィールドを変更する

ドロップダウンの値が変更されたときに、入力テキストフィールドの値を動的に変更しようとしています。私のページの

ヘッド:私はjQueryを使って任意の問題があるではないもの、それはすべての非常に簡単だん

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 
    <link rel="stylesheet" type="text/css" href="mystyle.css" /> 
    <script type="text/javascript" src="projectJS.js"></script> 
    <script type="text/javascript" src="jquery.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      // initialize the value of the input field to the selected value 
      // of the dropdown list: 
      $("#membfee").val($("#role").val()); 

      $("#role").click(function() { 
       // when the value of the dropdown list changes 
       // update the input field 
       $("#membfee").val("111"); 
      }); 
     });​ 
    </script>   
</head> 

。あなたは上記のように外部のjavascriptファイルとjqueryを参照することができますか?私は更新したいドロップダウンメニューとテキストフィールドを含む身体の

章:

<tr> 
    <td class="label_block">Membership Term:</td> 
    <td> <select name="role" id="role" /> 
       <option value="Trial">Trial</option> 
       <option value="1 Month">1 Month</option> 
       <option value="3 Month">3 Month</option> 
       <option value="6 Month">6 Month</option> 
       <option value="Year">Year</option> 
      </select> 
    </td> 
</tr> 
<tr> 
    <td class ="label_block">Membership Fee:</td> 
    <td><input type="text" size="15" name="membfee" id="membfee" value="" /></td> 
    <td class="error"> 
     <%out.print(membfee_msg);%> 
    </td> 
</tr> 

答えて

2

あなたは.change()を使用する必要があります。

$("#role").change(function() { 
    // when the value of the dropdown list changes 
    // update the input field 
    $("#membfee").val("111"); 
}); 

あなたは上の任意のJSのエラーがないことを確認ですページ、それはjust should workです。

+0

申し訳ありませんが、私は実際に.change()関数としてそれを持っていたし、ちょうどそれを試してみるだけで、クリックメソッドを持っていました。 – user1207869

+0

それは動作するはずです。おそらくページにエラーがありますか? ProtectJSとは何ですか?たぶんjQueryと競合します。 – PeeHaa

+0

projectjs.jsにはいくつかの機能がありますが、どちらも参照できないのではないかと心配しましたが、javascriptファイルにリンクする行をコメントアウトすると問題は解決しません。これは問題の可能性があるJSPファイルです。 – user1207869

1

ではなくchange()イベントを使用してみてください:

$("#role").change(function(){ 
    // blabla 
}) 
関連する問題