Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dropdown runs a query to populate checkboxes - ASP

Posted on 2003-11-21
2
Medium Priority
?
632 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

609 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