2012-05-14 6 views
0

こんにちは、私は、各ドロップダウンボックスでユーザーが選択したドロップダウン値を維持したい、このJQUERYを使用してドロップダウンボックスで選択した値を保持する方法は?

$(".selfont").change(function(event){ 

$('#dav').val(); 

window.location ='?davQ=' + $('#dav').val() + '&pathogenQ=' + $('#pathogen').val() + '&topicQ=' + $('#topicF').val() ; 

}); 

のようにjqueryのコードを使用しています。しかし、現在のところ、値はユーザーが選択したものではなく、常に最初の値を示します。 jqueryを使用してユーザーが選択した値でドロップダウンフィールドを設定するにはどうすればよいですか?私を助けてください。

私の最初の選択ボックスコードがフィールドに「いずれかを選択し、」我々はそれのように表示された値を選択した場合でも

<select name="dav" id="dav" style="width: 275px" class='selfont' > 
<option value='' class=''>Select one</option> 
         <?php 

           $test = mysql_query("SELECT DISTINCT DataVersion FROM olivesdeptable ORDER BY DataVersion DESC"); 
           $i=1; 
           while($numval=mysql_fetch_array($test)) 
           { 
              print "<option value=\"".$numval['DataVersion']."\">".$numval['DataVersion']."</option>"; 
              $i=$i+1; 
            } 
          ?> 

        </select> 

を下回るようなものです。偶数値が更新されるドロップダウンフィールド

<script type="text/javascript"> 

if (document.getElementById("dav").selectedIndex < 1) 
{ 
document.getElementById('pathogen').selectedIndex = ""; 
document.getElementById('pathogen').disabled = true; 
} 

if (document.getElementById("pathogen").selectedIndex < 1) 
{ 
document.getElementById('topicF').selectedIndex = ""; 
document.getElementById('topicF').disabled = true; 
} 

if (document.getElementById("topicF").selectedIndex < 1) 
{ 
document.getElementById('ind').selectedIndex = ""; 
document.getElementById('ind').disabled = true; 
} 

if (document.getElementById("ind").selectedIndex < 1) 
{ 
document.getElementById('subind').selectedIndex = ""; 
document.getElementById('subind').disabled = true; 
} 

if (document.getElementById("subind").selectedIndex < 1) 
{ 
document.getElementById('countryR').selectedIndex = ""; 
document.getElementById('countryRF').options.length = 0; 
document.getElementById('countryRF').selectedIndex = ""; 
document.getElementById('countryR').disabled = true; 
document.getElementById('countryRF').disabled = true; 
} 

</script> 

ためのJavaScriptコード

、ボックス2番目のドロップダウンは無効として表示されますか?最初のドロップボックスの値が次のDropboxの値のために働いている

<select name="pathogen" id="pathogen" style="width: 275px" class='selfont' > 
    <option value=''>Select one</option> 
          <?php 

            $test = mysql_query("SELECT DISTINCT Pathogen FROM olivesdeptable where DataVersion='$davQ' ORDER BY Pathogen ASC"); 
            $i=1; 
            while($numval=mysql_fetch_array($test)) 
            { 
               print "<option value=\"".$numval['Pathogen']."\">".$numval['Pathogen']."</option>"; 
               $i=$i+1; 
             } 
           ?> 

        </select> 

以下のよう

次のドロップダウンフィールドのマークアップがされているURLに保存するが、ページ内の値は「いずれかを選択」と表示されますか? uは私たちのためにセットアップフィドルをすることができますuはウルHTMLマークアップを表示する必要が

+1

をソートするために役立つ、またはください、http://jsfiddle.net resposeため –

+0

おかげで、私は質問を更新しました。 – Gopipuli

+0

URLはlistboxで選択された値で更新されますが、リストボックスでは最初の値 "Select one"が表示されますか? – Gopipuli

答えて

0
<?php 

    $test = mysql_query("SELECT DISTINCT DataVersion FROM olivesdeptable ORDER BY DataVersion DESC"); 
    $i=1; 
    $selected = ''; 
    // make compare with the value you want to select with the parameter form url 
    // here I assume $_GET['davQ'] holds the value to $numval['DataVersion'] 
    if($_GET['davQ'] == $numval['DataVersion']) $selected = 'selected'; 
    while($numval=mysql_fetch_array($test)) 
    { 
    echo "<option value=\"".$numval['DataVersion']."\" $selected>".$numval['DataVersion']."</option>"; 
    $i=$i+1; 
    } 
?> 
1
$(document).ready(function() { 
      $('#dav').val(getURLParameter('davQ')); 

      $('#pathogenQ').val(getURLParameter('pathogenQ')); 

      $('#topicQ').val(getURLParameter('topicQ')); 

      $(".selfont").change(function (event) { 
       window.location = '?davQ=' + $('#dav').val() + '&pathogenQ=' + $('#pathogen').val() + '&topicQ=' + $('#topicF').val(); 
      }); 

      function getURLParameter(name) { 
      return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]); 
      } 
     }); 
+0

非常にありがとう、コードは、その正常に動作しますが、私は私の質問で上に更新されているフィールドのために実行しているJavaScriptコードを持っている。最初のフィールドが更新された後も、2番目のフィールドはまだ無効になっていますか?何か変更が必要ですか? plsは助けて...あらかじめ感謝します。 – Gopipuli

+0

コードに何か追加する必要がありますか? – Gopipuli

+0

ドロップダウンボックスで毎回値が選択され、window.locationパラメータおよびnext selectオプションで更新された値が最初に有効になります。 – Gopipuli

関連する問題