Solved

Dropdown runs a query to populate checkboxes - ASP

Posted on 2003-11-21
2
621 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
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 look for a specific file type in a local or remote server directory using PHP.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now