Solved

Dropdown runs a query to populate checkboxes - ASP

Posted on 2003-11-21
2
623 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
2 Comments
 
LVL 15

Accepted Solution

by:
VincentPuglia earned 20 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.

831 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