?
Solved

Dropdown runs a query to populate checkboxes - ASP

Posted on 2003-11-21
2
Medium Priority
?
628 Views
Last Modified: 2007-12-19
Hello,

I have an ASP form that has a dynamic dropdown list.  I need the user's selection in the list to populate the form's checkboxes as either being checked or unchecked.

Ie.  In the admin maintenance section the admin will select from a drop down list values such as Admin, Marketing, Accounting, Finance, Sales, etc... the selection will populate checkboxes that represent their access levels, such as Full Access, Limited Access, etc..

The problem with the code that I have now is that it won't allow for a selection.  It keeps submitting the first item and won't allow the user to select any other items.

<select name="Role" onClick="onChangeRole()">
<%
dim oneRole
dim nRoleId
      
sSQL = "SELECT * FROM Role"
set oRs = Server.CreateObject("ADODB.Recordset")
oRs.Open sSQL, oConn,3,3

if not ors.EOF then  ' check to see if recordset empty

oRs.MoveFirst

Do while not oRs.EOF

oneRole = ors.Fields("role")
if strRoleSelected = oneRole then
nRoleId = ors.Fields("roleID")
Response.Write "<option selected  value='" & strRoleSelected & "'>" & strRoleSelected
else
Response.Write "<option  value='" & oneRole & "'>" & oneRole
end if

ors.MoveNext
loop

end if

oRs.Close
oConn.Close

%>
</option>
</select>



<SCRIPT LANGUAGE="JavaScript">
<!--
function onChangeRole()
{
      var GuiList = eval("document.forms[0].Role");
      var strRole = GuiList.value;
      document.forms[0].action = "ChangeRoles.asp?Role=" + strRole;
      document.forms[0].submit();
      
}
function onClickSave()
{
      document.forms[1].submit();
}

// -->

</SCRIPT>
0
Comment
Question by:tmacfarlane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
VincentPuglia earned 80 total points
ID: 9798316
Hi,

  Not exactly certain what you want, but....

1) you should probably be using the onchange event handler, not the onclick event handler.  As soon as the user tries displaying the drop down, s/he is clicking -- so the selected option (if any) will be submitted.

<select name="Role" onchange="onChangeRole()">

2) if you want more than one option to be selected, you need to make the select element 'multiple' :

<select name="Role" multiple onchange="onChangeRole()">


3) Also, you probably should send the form object and the selected option's value to the function so that if the form moves from position '0' to position 'x', it doesn't crash and require a rewrite:

<select name="Role"  onchange="onChangeRole(this.form, this.options[this.selectedIndex].value)">

function onChangeRole(formObj, strRole)
{
    formObj.action = "ChangeRoles.asp?Role=" + strRole;
    formObj.submit();
     
}

Vinny
0
 

Author Comment

by:tmacfarlane
ID: 9798771
thanks.  you put me on the right track.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question