Solved

onchage event

Posted on 2015-02-23
7
42 Views
Last Modified: 2015-02-26
So, the onchage event that I have in my drop down is not firing.  Any ideas?

function getGroups(){
  $().SPServices({
            operation: "GetGroupCollectionFromWeb",
            webURL: siteURL,
            async: false,
            completefunc: function (xData, Status) {
              //console.log(xData.responseXML);
              $(xData.responseXML).find("Group").each(function() {
                //var names = $(this).attr("LoginName");
                var id = $(this).attr("ID");
                
                $("#WSOutput").append("<option value="+ $(this).attr("Name") +">" + $(this).attr("Name") + "</option>");
                
              });
            }
        });
		
		//Capture selected value
		var groupSelection =  document.getElementById("WSOutput").value; //ADDED
		
		console.log("selected value: "+groupSelection);
		//Call getGroupUsers() function to filter
		getGroupUsers(groupSelection); //ADDED
}

//returns users from group
function getGroupUsers(group){
		//var dfd = $.Deferred();
		alert(group);
	console.log("In getGroupUsers function");
		($().SPServices({
			operation: "GetUserCollectionFromGroup",
			groupName: group, //ADDED
			async: true
		})).done(function(responseXML, status){
			var d = [];

			var nodes = $(responseXML).SPFilterNode("User")
			if (nodes.length > 0){
				nodes.each(function(){
					var uId = $(this).attr("ID");
					var uName = $(this).attr("Name");
					var uLoginName =$(this).attr("LoginName");	
					var uEmail = $(this).attr("Email");
					//var uTitle = $(this).attr("Title");
					console.log("uEmail");
					//alert("I'm in");	
					$("#users").append("<table id='uTbl'><tr><td>" + uId + "</td><td>" + uName + "</td><td>" + "<a href='mailto:" + uEmail + "'>"+ uEmail +"</a></td></tr></table>");	
				});
			}
		});
}	

});
</script>
<style>
#uTbl  {
	width:100%;
	border-collapse: collapse;
	table-layout: fixed;
}
table#uTbl, #uTbl td {
	border:1px solid #ccc;
}
#uTbl td {
	padding: 5px;
}

</style>
<select id="WSOutput" onchange="getGroups()"> //ADDED EVENT
<select id="nameSelect">
<div id="users"></div>

<div id="myOutDiv"></div>

Open in new window

0
Comment
Question by:Isaac
  • 3
  • 2
  • 2
7 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 40626718
Hi,
hm, have you closed the select tag?
Can you please simply try to replace
<select id="WSOutput" onchange="getGroups()"> //ADDED EVENT
<select id="nameSelect">

Open in new window

with
<select id="WSOutput" onchange="getGroups()" /> //ADDED EVENT
<select id="nameSelect" />

Open in new window


Javascript / jQuery can be very picky as soon as the HTMLDOM is not valid.

HTH
Rainer
0
 
LVL 5

Author Comment

by:Isaac
ID: 40626913
Closed it but that didn't work.
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 40626956
Hi,
hm, could you perhaps attach the complete generated HTML source?
Second question: why do you want to call the getGroups function in the onchange? Shouldnt this be the getGroupUsers? Because in the latter one you build up the select and multiple calls will simply append the same groups again and again.
Thanks.
Rainer
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 40627011
Might sound obvious, but in the code you posted, you don't have any <options> in the <select>, meaning there's nothing to change it to: it's never going to fire a change() event!
0
 
LVL 5

Author Comment

by:Isaac
ID: 40627021
Here's what I'm trying to do,

I want to show users in a group based on the selection of a group from a drop down box.

@Chris, <options> is dynamically added.

Here's the page http://isaac.issharepoint.com/practice/Web%20Part%20Pages/test.aspx
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 40627025
On the page you posted, the <select> is not dynamically populated - it's empty!
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 40627049
Hi,
thanks. Due to missing credentials, the SPServices call does not return anything.

BTW, when using IE 11 to open the page, I get two Javascript errors:
Line 824: var logoImg = documentGetElementsByName('onetidHeadbnnr0');
There is a missing "." and should be
var logoImg = document.GetElementsByName('onetidHeadbnnr0');

And the next one a couple of lines later:
MoveSiteTitle(); - this function cannot be found.

HTH
Rainer
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio npm 1 29
testing a web application for ipad on windows pc 3 34
Html split(text) Part2 6 20
Add somewhat of a wildcard to your javascript 12 30
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 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