Avatar of net-workx
net-workx
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Pre-select options from a select drop down using jQuery and ASP

I have just been working on a question with hielo (https://www.experts-exchange.com/questions/25196926/jquery-related-selects-drop-down-menus-in-ASP-classic.html?anchorAnswerId=26832665#a26832665)  which has now been resolved.

Basically my script has three linked drop down select boxes, these pull from three tables (depts, cat, subcats) all related with ID numbers

The state its in at the momement is working perfectly for example if i wanted to add a new product (ie. there there are no pre-defined values for the dept, cat or subcat)

my new question (this one!) it how can i now pass values which i can set as variables in asp such as

<%
deptID = RS("intDepartmentID")
catID = RS("intCategoryID")
subcatID = RS("intSubCategoryID")
%>

to my data processor page (which returns the values needed for the drop downs) so that if there is a variable set, it does a response.write on the option group and when you view the webpage, it pre-selects that option.

The code is as follows:

index.asp:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<!--#include virtual="/common/includes/analytics.asp"-->
<!--#include virtual="/common/includes/functions.asp"-->
<!--#include virtual="/common/includes/personalisation.asp"-->
<!--#include virtual="/common/includes/connection_string.asp"-->

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>jQuery Related Selects</title>

<script src="/common/jQuery/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="/common/jQuery/plugins/related-selects/jquery.relatedselects.min.js" type="text/javascript"></script>

<style type="text/css">
      body { font:12px helvetica, arial, sans-serif; }
</style>

<script type="text/javascript">
$(function(){

      $("#depts").relatedSelects({
            onChangeLoad: 'datasupplier.asp',
            dataType: 'html',
            selects: ['deptID', 'catID', 'subcatID']
      });
});
</script>

</head>

<body>

<h1>jQuery Related Selects Plugin</h1>


<h2>Example</h2>
<form id="depts" method="post" action="/common/jQuery/plugins/related-selects/results.asp">
      <%
      Set RSdept = Server.CreateObject("ADODB.Recordset")
      SQLdept = "SELECT * FROM tblCategoryDepartments WHERE intWebDepartment = 1 AND intActive = 1 ORDER BY txtDepartmentName"
      RSdept.OPEN SQLdept,Connection,3,3
      %>
      
      <select name="deptID">
            <option value="">Choose Dept »</option>
            <% Do While Not RSDept.EOF %>
            <option value="<% =RSdept("intDepartmentID") %>"><% =RSdept("txtDepartmentName") %></option>
            <%
            RSDept.MoveNext
            Loop
            %>
      </select>
      
      <%
      RSdept.Close
      Set RSdept = Nothing
      SQLdept = ""
      %>
      
      <select name="catID">
            <option value="">Choose Category »</option>
      </select>
      
      <select name="subcatID">
            <option value="">Choose SubCategory »</option>
      </select>
      <input name="Submit1" type="submit" value="submit" />
</form>

</body>
</html>

datasupplier.asp:
<!--#include virtual="/common/includes/functions.asp"-->
<!--#include virtual="/common/includes/personalisation.asp"-->
<!--#include virtual="/common/includes/connection_string.asp"-->
 
<%
If ""<>Trim(Request("catID")) Then
      SQL = "SELECT intSubCategoryID, txtCategoryName FROM tblProductSubCategories WHERE intMasterCategoryID = " & Request("catID") & " AND intWebCategory = 1 AND intActive = 1 ORDER BY txtCategoryName"
ELSEIF ""<>Trim(Request("deptID")) Then
      SQL = "SELECT intCategoryID, txtCategoryName FROM tblProductCategories WHERE intDepartmentID = " & Request("deptID") & " AND intWebCategory = 1 AND intActive = 1 ORDER BY txtCategoryName"
END IF
 
 
      Set RS = Server.CreateObject("ADODB.Recordset")
      RS.Open SQL,Connection,1,3
 
      Do While Not RS.EOF
      %>
            <option value="<%=RS.Fields(0).value %>"><% =RS.Fields(1).value %></option>
      <%
      RS.MoveNext
      Loop
       
      RS.Close
      Set RS = Nothing
%>

The idea being that with in the Do While Not RS.EOF loop in datasupplier.asp:

IF  RS.Fields(0) = catID THEN Response.Write "selected"

does anyone have an idea about how to achive this?

thanks
ASPjQueryHTML

Avatar of undefined
Last Comment
hielo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
hielo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck