<form action="samma_sida.asp">
<select name="sel" onchange="this.form.submit()">
<option value="1">Test1</option>
<option value="2">Test2</option>
<option value="3">Test3</option>
</select>
</form>
<%
dim rq
rq = request.querystring("sel") & ""
if len(rq) > 0 and isnumeric(rq) then
Visa = "SELECT * FROM test WHERE ID = " & clng(rq)
' ...
end if
%>
Du kan ju även använda AJAX, kom jag på. Ett exempel; sidan med formuläret
<style type="text/css">
#holder{ display: none; }
</style>
<script type="text/javascript">
function getReq(){
return typeof(ActiveXObject) == "function" ?
new ActiveXObject("Microsoft.XMLHTTP") :
typeof(XMLHttpRequest) != "undefined" ? new XMLHttpRequest() : null;
}
function updateSel(obj, sel){
var req = {o:getReq(),s:obj,t:sel};
if (req){
var id = obj.options[obj.selectedIndex].value;
req.o.open("GET", "http://localhost/process.asp?id=" + id, true);
req.o.onreadystatechange = function(){
if (req.o.readyState == 4){
parseAndUpdate(req);
}
}
req.o.send(null);
}
}
function parseAndUpdate(rt){
var txt = rt.o.responseText,
val = txt.match(/<value>((?:.|\n)*?)<\/value>/),
hl = txt.match(/<headline>((?:.|\n)*?)<\/headline>/);
if (val && hl){
rt.s.form.elements[rt.t].options[0] = new Option(val[1], hl[1]);
document.getElementById("holder").style.display = "block";
}
}
</script>
<form>
<select name="sel" onchange="updateSel(this, 'sel2')">
<option value="1">Test1</option>
<option value="2">Test2</option>
<option value="3">Test3</option>
</select>
<div id="holder">
<select name="sel2"></select>
</div>
</form>
Sedan skapar du en sida process.asp, som sköter databaskommunikationen:
<%
dim rq
rq = request.querystring("id")
if len(rq) > 0 and isnumeric(rq) then
dim sql
sql = "select id, rubrik from test where id = " & clng(rq)
dim conn, rs
set conn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
conn.open "provider=microsoft.jet.oledb.4.0; data source=" & server.mappath("/[b]din_databas[/b].mdb")
rs.open sql, conn
if not rs.eof then
response.write "<value>" & rs("id") & "</value><headline>" & rs("rubrik") & "</headline>"
end if
rs.close
set rs = nothing
conn.close
set conn = nothing
end if
%>
272 ms totalt · 4 externa anrop · v20260731065814-full.51f67c91