2013-01-10 93 views
2

我正在使用jquery刷新頁面,當有人在下拉菜單中選擇一個項目時。但是,它將旋轉回所選的默認值。如何使用jquery刷新後保持下拉選擇

(這可以防止使同時使用下拉菜單搜索用戶。)

如何獲得下拉保存頁面上選擇該項目刷新?

下面的代碼:

<%@ LANGUAGE="VBSCRIPT" %> 
<% 
pagetitle="Contractor Details" 
%> 
<!--#INCLUDE VIRTUAL="/_lib/include/header.htm"--> 
<!--#INCLUDE VIRTUAL="/_lib/include/menu.htm"--> 
<script> 
$(document).ready(function() { 
    $("#abn,#cat").change(function() { 
    this.form.submit(); 
}) 
}); 
</script> 
<div class="twoColumnRow"> 
<div class="twoColumnContent"> 
<p class="breadCrm"><a href="/index.htm">Home</a> <span>&gt;</span> <a href="/tools/index.htm">Tools of the Trade</a> <span>&gt;</span> <a href="/tools/finance/index.htm">Finance and Purchasing</a><span>&gt;</span> <a href="/tools/finance/procurement/index.htm">Procurement and Contracts information</a></p> 
<div class="contentPad"> 
<!-- Start of main content --> 

<p class="imageRight">&nbsp;</p> 
<h1><%=pagetitle%></h1> 

<% 
     Dim connectString, connect, conDB, sconDB, con, scon, src_abn, src_cat 
     connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("data") 
       src_abn = Request.QueryString("abn") 
       src_cat = Request.QueryString("cat") 
     set connect = Server.CreateObject("ADODB.connection") 
     connect.open connectString 

     if src_abn = "all" and src_cat = "all" then 
     conDB = "SELECT * FROM cont.csv"  
     elseif src_abn = "all" then 
     conDB = "SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes'" 
     elseif src_cat = "all" then 
     conDB = "SELECT * FROM cont.csv WHERE ucase(abn) LIKE ucase('%"+src_abn+"%')" 
     else 
     conDB = " SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes' AND ucase(abn) LIKE ucase('%"+src_abn+"%')" 
     end if 

     sconDB = "SELECT * FROM cont.csv" 

     set con = connect.execute(conDB) 
     set scon = connect.execute(sconDB) 
%> 
<h2>Search results</h2><hr /> 
<% if not con.BOF then %> 
<div style="margin-top:1em"> 

    <form action="dbresults.htm" method="get"> 

     <p>Company name:<br/> 
     <select id="abn" name="abn"> 
     <option label="All companies" value="all"></option> 
     <% while (NOT scon.EOF) %> 
     <option label="<%=scon("legal")%>" value="<%=scon("abn")%>"></option> 
     <%scon.MoveNext() 
          Wend %> 
     </select> 
     </p> 
    <p>Categories for Creative Design:<br/> 
     <select id="cat" name="cat"> 
     <option class="group" label="All categories" value="all"></option> 
     <option class="group" label="Strategic brand, marketing and communications advice" value="a"></option> 
     <option class="group" label="Graphic design and layout" value="b"></option> 
     <option class="group" label="Forms design" value="c"></option> 
     <option class="group" label="Web design and development" value="d"></option> 
     <option class="group" label="Authoring services" value="e"></option> 
     <option class="group" label="Editorial services" value="f"></option> 
     <option class="group" label="Translation services" value="g"></option> 
     <option class="group" label="Photography and film services" value="h"></option> 
     <option class="group" label="Scanning and digitisation services" value="i"></option> 
     <option class="group" label="Multimedia editing services" value="j"></option> 
     </select> 
    </p> 
    <input type="submit" value="Search" /> 
    </form> 
    <br /><hr /> 

    <table style="font-size:.9em;" class="contentTable"> 
      <tr> 
       <th>ABN:</th> 
       <th>Company Name:</td> 
      </tr> 
    <% con.Movefirst() %> 
    <% while (NOT con.EOF) %> 
      <tr> 
       <td><%=con("abn")%></th> 
       <td><a href="dbcomp.htm?abn=<%=con("abn")%>&cat=all"><%=con("legal")%></a></td> 
      </tr> 
    <% 
    con.MoveNext() 
    Wend 
    %> 
</table> 

</div> 
<% else %> 
    <% scon.Movefirst() %> 
    <form action="dbresults.htm" method="get"> 

     <p>Company name:<br/> 
     <select name="abn"> 
     <option label="All companies" value="all"></option> 
     <% while (NOT scon.EOF) %> 
     <option label="<%=scon("legal")%>" value="<%=scon("abn")%>"></option> 
     <%scon.MoveNext() 
          Wend %> 
     </select> 
     </p> 
    <p>Categories for Creative Design:<br/> 
     <select name="cat"> 
     <option label="All categories" value="all"></option> 
     <option label="Strategic brand, marketing and communications advice" value="a"></option> 
     <option label="Graphic design and layout" value="b"></option> 
     <option label="Forms design" value="c"></option> 
     <option label="Web design and development" value="d"></option> 
     <option label="Authoring services" value="e"></option> 
     <option label="Editorial services" value="f"></option> 
     <option label="Translation services" value="g"></option> 
     <option label="Photography and film services" value="h"></option> 
     <option label="Scanning and digitisation services" value="i"></option> 
     <option label="Multimedia editing services" value="j"></option> 
     </select> 
    </p> 
    <input type="submit" value="Search" /> 
    </form> 
    <br /><hr /> 
<p>No records match your query.</p> 
<p><a href="dbtest.htm">Return to search page</a></p> 
<% 
    end if 
    con.close 
%> 


<!-- End of main content --> 
</div> <!-- end contentPad div --> 
</div> <!-- end twocolumncontent div --> 
<div class="twoColumnLinks"> 

<!--<div class="relatedLinks"> 
<h3>Related Links</h3> 
<ul> 
<li><a href="/index.htm">Related link 1</a></li> 
</ul> 
</div>--> <!-- end relatedlinks div --> 
<!--#INCLUDE VIRTUAL="/_lib/include/quicklinks.htm"--> 
<!--#INCLUDE VIRTUAL="/_lib/include/mylinks.htm"--> 
</div> <!-- end twocolumnlinks div --> 
</div> <!-- end twocolumnrow div --> 
<!--#INCLUDE VIRTUAL="/_lib/include/footer.htm"--> 
+0

必須在這個答案的檢查:http://stackoverflow.com/questions/2487783/drop-down-not-retaining-selected-value-after-post-back –

+0

我試過了,但它不起作用。他指出,如果方法得到,它將不得不進行調整。我會怎麼做? – sephiith

+0

獲取值取自request.querystring(「varname」)而不是request.form(「varname」) –

回答

1

「選擇」 屬性添加到您選擇的選項標籤:

<option label="some label" value="some value" selected>Some text</option> 
+0

我已經將該選項添加到默認選定選項,但是如何才能將該選項應用到之後選擇的標記刷新? (它保持恢復到默認狀態) – sephiith