Backslashes in values ​​/ selectors

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 want to automatically select values ​​using javascript. This is the code I'm 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 any quirk I should know that this would prevent IE7 from working properly?

+4
source share
1 answer

seems to work .. with jquery 1.9

http://jsfiddle.net/2nGnm/

HTML:

 <select id="Printers" multiple="multiple" name="Printers"> <option value="\\ABCDEF01\PRINTER1\">\\ABCDEF01\PRINTER1\</option> <option value="\\ABCDEF02\PRINTER2">\\ABCDEF02\PRINTER2</option> </select> 

JS:

 var select = document.getElementById('Printers'); var escapedName = $('[name="Printers"] option:last').val().replace(/\\/g, "\\\\"); // Escape backslashes. $('option[value="' + escapedName + '"]').prop('selected', true); 
0
source

All Articles