Javascript value to MySQL Select -
i have form select , options choose from. select option values brought asp classic loop.
the second select filled javascript based on first select value has been made. sends value out by
var newoption = document.createelement("option"); newoption.value = "2015"; newoption.innerhtml = "year"; s2.options.add(newoption);
so want expand bring mysql recordset (without submitting yet) based on second select choice have been made
set package = objconn.execute ("select * pack_plan idpack = "js.value??"")
so want able receive value , select records it. , have no idea how done. appreciated.
the following solution works fine me. since don't want reload page need make asynchronous request retrieve values of second select according choice user makes on first select. on page have form selects , few lines of javascript make asynchronous call.
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> function jsfunc1(primaryjsvalue){ $.ajax({url:"http://www.yoursite.com/secondary_list.asp?reqvalue="+primaryjsvalue.value, success:function(result){ if (result == "errore") { $("#thesecondarylist").html('error'); } else { $("#thesecondarylist").html(result); } }}); } </script> <select id="selectid1" name="primaryselect" onchange="jsfunc1(this)"> <option value="val1" id="valid1"> val1 </option> <option value="val2" id="valid2"> val2 </option> <option value="val3" id="valid3"> val3 </option> </select> <div id="thesecondarylist"> <select id="selectid2" name="secondaryselect" > <option value="" id=""> choose primary list see available values </option> </select> </div>
the secondary_list.asp page query db according option selected on main page, , loop each value writing response content of "thesecondarylist" div.
so contain code open connection, query db , print second select option filled db.
your asp file can directly start with:
basically code
set package = objconn.execute ("select * pack_plan idpack = "js.value??"")
become
set package = objconn.execute ("select * pack_plan idpack = "&request.querystring("reqvalue")&"") '... retrieve records ... %> <select id="selectid2" name="secondaryselect" > <% while not rssecondlist.eof thevalue = rssecondlist("packname") theid = rssecondlist("idpack") %> <option value="<%=thevalue%>" id="<%=theid%>"> <%=thevalue%> </option> <% rssecondlist.movenext wend %> </select>
Comments
Post a Comment