2012-04-22 14 views
-1

enter image description hereI am working on my school application using jsp and web-development is new to me. At this moment I am stumbled upon the issue:<a href link..> when <SELECTED> value is changed

The process should be this:

I have a Dropdown box with multiple values. For example:

Room: 111 | Building: ACC | Capacity: 15

Room: 111 | Building: ACD | Capacity: 25

Room: 151 | Building: ACC | Capacity: 11

Room: 113 | Building: ACC | Capacity: 15

When user selects ANY option nothing should happen.

Next to the dropdown box, I have a <a href link..> which sais "see the chart".

When user presses "see the chart" the following process should take place:

  1. String in selected box should be separated and Room# and Bulding# must be extracted into separate strings
  2. new windowshould open with this link: room_chart.jsp?room=111&building=ACC (for example)

I know how to split the string and do it in general, but I don't know how to dynamically do it without reloading the page... I guess I would need to implement the JavaScript?

答えて

2

Call a Javascript function in the anchor's href attribute. In that function use document.getElementById with the select box's id to get the selected stringを動的に更新して分割し、ajaxリクエストを送信するか、window.openという新しいウィンドウを開きます(動的ではありません)。

<html> 
    <script type="text/javascript"> 
     function view_chart() { 
      var select = document.getElementById("room_select"); 
      var option = select.options.item(select.selectedIndex).value; 
      var tokens = option.split(/[:|]/); 
      var url = "room_chart.jsp?room="+trim(tokens[1])+"&building="+trim(tokens[3]); 
      window.open(url); 
     } 

     function trim(value) { 
      value = value.replace(/^\s+/,''); 
      value = value.replace(/\s+$/,''); 
      return value; 
     } 
    </script> 
    <body> 
     <select id="room_select"> 
      <option>Room: 014 | Building: ACT</option> 
      <option>Room: 005 | Building: ACC</option> 
     </select> 
     <a href="javascript:view_chart()">Show Info</a> 
    </body> 
</html> 
+0

私はあなたを投票する人ではありませんでしたが、それはかなり悪いアクセシビリティだと言えるでしょう。リンクがどこにあるかわからない、新しいタブで開くことができないなど – jpsimons

+0

私は自分の答えを更新しました。 – blackcompe

+1

"十分ではないjQuery"ツの推測免責事項:私はあなたの答えをdownvoteしなかったhttp://www.doxdesk.com/img/updates/20091116-so-large.gif http://meta.stackexchange.com/question/45176 /使用中のjquery-not-a-valid-a-javascript質問/ 48195#48195 –

0

のthats可能な場合は、DORPダウンからの選択に基づいて更新されたURLを持つブランドの新しい要素、とのhref要素を置き換えるために、jqueryのを使用することができます。

関連する問題