I'm trying to make a filter which has a lot of options that get listed in the top of the filter box, now, I'm trying to add the countries and I decided to use regex. But I can't get it to work, for some reason it replaces in the middle of the string instead of the beginning.
JS Code:
function countryCheck(object) {
var filter = document.getElementById("search_filter");
var re = new RegExp("<b>Location<\/b>:\s[a-zA-Z\s]+\s\|\s");
filter.innerHTML = filter.innerHTML.replace(re, ("<b>Location</b>: " + object.value.replace(" ", "") + " | "));
}
HTML Code:
<div id='search_filter'><b>Filter</b>: <b>Location</b>: Anywhere | <b>Player Slots</b>: >=0/>=0</div>
<br />
<select class='select' style='width:100%;' onchange='countryCheck(this);'>
<option>Anywhere</option>
<option>Europe</option>
<option> Sweden</option>
<option> Germany</option>
<option> United Kingdom</option>
<option> France</option>
<option>North America</option>
<option> Canada</option>
<option> United States</option>
<option> Mexico</option>
</select>
jsFiddle showing what the problem is: jsFiddle
I'm trying to make so it replaces the current <b>Location</b>: [some country] |
with <b>Location</b>: [some other country] |
class
orid
and replace the content directly?<optgroup>
.