From last three days I have been trying to fix these but am not able to resolve them. Here is my query if someone can help me.
I am having some dropdowns on my page that contain some security related question, if user already selected question No 1 from first down then in all remaining dropdowns first question should be disabled, then same scenario should apply for remaining dropdown.
I have created my my script but as everybody in IE7 disabled attribute is not working so I have created custom script to make select list values disabled but tha'ts not working in first click..
html
<select name="select1" class="securityQuestions">
<option value="0">Please select an option...</option>
<option value="1">What is your favorite color?</option>
<option value="2">What is your pet's name?</option>
<option value="3">How old are you?</option>
</select>
<select name="select2" class="securityQuestions">
<option value="0">Please select an option...</option>
<option value="1">What is your favorite color?</option>
<option value="2">What is your pet's name?</option>
<option value="3">How old are you?</option>
</select>
<select name="select3" class="securityQuestions">
<option value="0">Please select an option...</option>
<option value="1">What is your favorite color?</option>
<option value="2">What is your pet's name?</option>
<option value="3">How old are you?</option>
</select>
Here is my script to make
generic script
(function($){
$.fn.removeQuestions = function() {
var wholeList = $(this);
wholeList.focus(function() {
// no of question lists on the page
var listLength = wholeList.length;
// array to hold which questions have been selected
var questionArray = new Array(listLength);
// loop to find index of questions selected, store in array
$('option:selected').each(function(index, value) {
questionArray[index] = $(this).index();
});
// loop over all question lists
wholeList.each(functio开发者_运维百科n(index, value) {
// remove any existing attr from previous selection
$('option', this).removeAttr('disabled');
// for each list hide each question in array
for(j = 0; j <= questionArray.length; j++) {
// don't hide if it's default 'choose your question'
if(!questionArray[j] == 0) {
$('option', this).eq(questionArray[j]).attr('disabled','disabled');
}
}
// now re-show the question selected in this list item.
$('option', this).eq(questionArray[index]).removeAttr('disabled');
});
});
return wholeList;
}; // end of plugin
})(jQuery);
(function($) {
$('select').change(function() {
if(this.options[this.selectedIndex].disabled) {
// Needs revision!
if (this.options.length == 0) {
this.selectedIndex = -1;
} else {
this.selectedIndex--;
}
$(this).trigger("change");
}
});
$('select').mousedown(function(){
$(this).children('option[disabled]').each(function() {
$(this).css({'color': '#cccccc'});
});
});
})(jQuery);
精彩评论