Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

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

Avatar of net-workx
net-workxFlag for United Kingdom of Great Britain and Northern Ireland asked on
1 Comment1 Solution1611 ViewsLast Modified:
I have just been working on a question with hielo (https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_25196926.html#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:

<!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">
<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; }

<script type="text/javascript">

            onChangeLoad: 'datasupplier.asp',
            dataType: 'html',
            selects: ['deptID', 'catID', 'subcatID']



<h1>jQuery Related Selects Plugin</h1>

<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>
      Set RSdept = Nothing
      SQLdept = ""
      <select name="catID">
            <option value="">Choose Category »</option>
      <select name="subcatID">
            <option value="">Choose SubCategory »</option>
      <input name="Submit1" type="submit" value="submit" />


<!--#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"
      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>
      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?