Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.
1 to 7 of 7
The problem with this one isn't that it's impossible to change the selected option automatically, but rather that the Safari UI doesn't care to reflect the change.
Here's the js:
jQuery.fn.selectOptions = function(value) {
this.each(
function() {
if(this.nodeName.toLowerCase() != "select") return;
// get number of options
var optionsLength = this.options.length;
for(var i = 0; i<optionsLength; i++) {
this.options[i].selected = false;
if (this.options[i].value == value) {
this.options[i].selected = true;
};
}
}
)
return this;
}
Not only do I have to set the initial selected values to false before making the change (that's what the this.options[i].selected = false; is for), but I also have to live with the fact that I have to manually click on the select element to see the change.
This problem is Safari only, or at least I believe it to be. What do you think?
this.options[i].selected = "selected"; does it work?
Nope. It was the first thing I tried, thinking that the problem would be a simple one.
This is for select options. I'll try to illustrate the behaviour in Safari.
Let's say the select box initially displays the text "First" and has the value of 1. The second option element is "Second" and has the value of 2.
The script tells Safari to change the selected option to be the "Second". Now, instead of displaying "Second" and having the value 2, it still displays "First" but has actually changed the value to 2. Now if I click the select box, I can see that the check mark is next to "Second".
I'll try adding the event handler, but I'm pretty sure the results will be the same.
Well, how about that. It worked when I added
$("#vari").addClass("outline");
$("#vari").removeClass("outline");
after calling selectOptions. It's an ugly trick for sure, but a necessary one. Now, if I could do the same by adding some sort of a highlight effect to the select box, there might be a way to get rid of the ugliness as well.
1 to 7 of 7