Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selectedIndex on a Multi-Select

Status
Not open for further replies.

jl8789

MIS
May 22, 2003
293
US
OK here is my code:
<script type="text/javascript">
var prev_si = '';

function UnselectActivePollingUser()
{
var user = document.userAdd.addUser[document.userAdd.addUser.selectedIndex].value;

if (user =='ActivePollingCard')
{
alert("This user currently has an Active Polling Card. The user cannot be moved into another group until the user is done selecting or skipped.");
document.forms['userAdd'].elements['addUser'].selectedIndex = prev_si;
}
}
</script>

<select name="addUser" multiple="true" size="5" onclick='prev_si = this.selectedIndex;' onchange="javascript:UnselectActivePollingUser();">

I have a multiselect with an onchange event that checks if the selected index is = 'ActivePollingCard'. It pops up an alert and tells the user they cannot select this one, and it sets them back to some other pre-selected index.

My problem is that I can select this value with other ones, and then it does not give me the alert because I have selected more than one value in the select box.

Is there a way to check if this value exists amongst multiple selects, and if it does fire the alert, and just re-set or set them back to another index. I don't care we reset the user to as long as they are not allowed to select that value at all, either by single selection or multiple selection. This needs to remain a multiple select.

PLEASE HELP!!
 
jl8789, does this help?


Code:
function UnselectActivePollingUser(s) {
    var o = s.options;
    for (var i = 0; i < o.length; i++) {
        if (o[i].selected && o[i].value == '2') {
		    alert('you cannot select 2');
			o[i].selected = false;
		}
	}
}

Code:
<select name="addUser" multiple="true" size="5" onchange="UnselectActivePollingUser(this);">

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Sorry, that was my test data. Here it is with your data:

Code:
function UnselectActivePollingUser(s) {
    var o = s.options;
    for (var i = 0; i < o.length; i++) {
        if (o[i].selected && o[i].value == 'ActivePollingCard') {
            alert("This user currently has an Active Polling Card. The user cannot be moved into another group until the user is done selecting or skipped.");
            o[i].selected = false;
        }
    }
}

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top