|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
What I'd like to do is the user be able to select particular employees hit a button and then it would perform an sql (insert/update) on the db depending on what was already preselected and what is now selected.
I just need your help with trying to figure out how to run a sql query on the selected options…if you have time to just swive through it, that'd be great. <SCRIPT> function getSelectedValues (select) { var r = new Array(); for (var i = 0; i < select.options.length; i++) if (select.options[i].selected) { r[r.length] = select.options[i].value; //alert(select.options[i].value); } return r; } </SCRIPT> <!--- store the selected Main_Group variable variable after the first select boxes submits itself ---> <cfif isDefined('form.select_Roles')> <cfset page.select_Roles = form.select_Roles> </cfif> <cfoutput> <form method="post" action="roles_select.cfm"> <!--- query DB for the first drop down list ---> <cfquery name="get_Roles" datasource="skillmatrix"> SELECT distinct users.title FROM users, ind_record WHERE ind_record.manager = '#trim(session.skillmatrixlastname)#, #trim(session.skillmatrixfirstname)#' </cfquery> <!--- first drop down list ---> <!--- NOTICE the onChange javascript event in the select tag, this is what submits the form after the first selection ---> <select name="select_Roles" required="yes" onchange="this.form.submit()"> <option>Select Main Group</option> <!--- dynamically populate the first drop down list based on the get_Roles query ---> <!--- NOTICE the CFIF within the option tag, this says, if the first selection has been made, display the chosen option when the page reloads ---> <cfloop query="get_Roles"> <option value="#title#" <cfif isDefined('form.select_Roles')><cfif form.select_Roles eq "#title#">selected</cfif></cfif>>#title#</option> </cfloop> </select> <p> <!--- if the first selection has been made, display the second drop down list with the appropriate results ---> <cfif isDefined('page.select_Roles')> <!--- query DB for second drop down list, based on the selected item from the first list ---> <cfquery name="get_Employees" datasource="skillmatrix"> SELECT users.employee_id, users.title, users.last_name, users.first_name FROM users, ind_record WHERE ind_record.manager = '#trim(session.skillmatrixlastname)#, #trim(session.skillmatrixfirstname)#' AND users.employee_id = ind_record.employee_id </cfquery> #get_Employees.recordcount# <!--- second drop down list ---> <select MULTIPLE size="10" name="select_Employee_Roles" required="yes"> <option>#form.select_Roles#(s) are highlighted</option> <!--- dynamically populate the second drop down list based on the get_Employees query ---> <cfloop query="get_Employees"> <option value="#employee_id#" <cfif isDefined('form.select_Roles')><cfif form.select_Roles eq "#title#">selected</cfif></cfif>>#last_name#, #first_name#, #title#</option> </cfloop> </select> <INPUT TYPE="button" VALUE="show selected values" ONCLICK="this.form.output.value = getSelectedValues(this.form.select_Employee_Roles) ;"> <!--<INPUT TYPE="button" VALUE="show selected values" ONCLICK="this.form.output.value = getSelectedValues(this.form.select_Employee_Roles) ;"> --> <INPUT TYPE="text" NAME="output" SIZE="80"> <input type="button" name="Submit" value="Submit"> </cfif> </form> </cfoutput> <CFIF IsDefined("FORM.output")> <CFoutpUT> <cfquery name="get_new" datasource="skillmatrix"> SELECT * FROM users WHERE employee_id = '#form.output#' </cfquery> </CFOUTPUT> <CFOutPUT>#get_new.title#</CFOutPUT> </CFIF> |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Cold Fusion Development > Javascript & CF |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|