I have two select elements. I tried to clean up my old code by making some variables global.
before I had something like this:
var user = $('#my_SiteUsers').val();
Problem was that now I could only get the value from this variable, at other times I may need something like the innerHTML and I'd rather not have to create a new variable for this.
So I created a global variable called user.
initiated at document.ready.But now my variable user and group aren't giving me the values I need. For example, the alerts are being triggers because default option isn't being picked up. Sorry if the question isn't clear. I can post old code if that helps.
$(document).ready(function(){
user = $('#my_SiteUsers');
group = $('#my_SiteGroups');
groupsAssigned = $("#my_SPGroupsAssigned");
groupAvailable = $("#my_SPGroupsAvailable");
userAssigned = $("#my_SPUsersAssigned").html("");
userAvailable = $("#my_SPUsersAvailable").html("");
$("button").click(function() { return false; });
populate();
});
function populate() {
//Populate the user list
strHTMLSiteUsers = "";
$().SPServices({
operation: "GetUserCollectionFromSite",
async: true,
completefunc: function(xData, Status) {
$(xData.responseXML).find("User").each(function() {
strHTMLSiteUsers += "<option value='" + $(this).attr("LoginName") + "'>" + $(this).attr("Name") + "</option>";
});
user.append(strHTMLSiteUsers);
}
});
if (user.val() == "default"){
//don't do anything
}else{
//if a user is selected, run
RefreshGroupLists();
}
//Populate the group list
strHTMLSiteGroups = "";
$().SPServices({
operation: "GetGroupCollectionFromSite",
async: true,
completefunc: function(xData, Status) {
$(xData.responseXML).find("Group").each(function() {
strHTMLSiteGroups += "<option value='" + $(this).attr("Name") + "'>" + $(this).attr("Name") + "</option>";
});
group.append(strHTMLSiteGroups);
}
});
if (group.val()=="default"){
//don't do anything
}else{
//if a user is selected, run
RefreshUserLists();
}
}
JSFiddle: http://jsfiddle.net/JevpS/