I have an HTML (multi)select list containing a list of network devices.
<select id="Printers" multiple="multiple" name="Printers">
<option value="\\ABCDEF01\PRINTER1\">\\ABCDEF01\PRINTER1\</option>
<option value="\\ABCDEF02\PRINTER2">\\ABCDEF02\PRINTER2</option>
...
...
</select>
I’m wanting to auto select values with javascript. This is the code I am currently using:
//Assume: val.Name == "\\ABCDEF02\PRINTER2"
var select = document.getElementById('Printers');
var escapedName = val.Name.replace(/\\/g, "\\\\"); // Escape backslashes.
$("option[value=\"" + escapedName + "\"]", select).attr('selected', 'selected');
This code works in chrome, but not in IE7. Is there a quirk I should know about that would prevent this from working correctly on IE7?
seems like working.. with jquery 1.9
http://jsfiddle.net/2nGnm/
html:
js: