Solved

Dropdown runs a query to populate checkboxes - ASP

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

821 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