My html:
<select onchange="getval(this);"> <option value="user1">user1</option> <option value="user2">user2</option> <option value="user3">user3</option> </select> <a class="local" href="http://subDomain.www.mysite.com">Site</a> <a class="local" href="http://subDomain.www.mysite.com/admin">Admin</a> <a class="local" href="javascript:open_wins('http://subDomain.mysite.com', 'http://subDomain.mysite.com/admin');">Both</a> My script:
<script> function getval(sel) { $(document).ready(function() { var x = (sel.value); var regex = new RegExp(Globally replace the subdomain of urls on select change); $('.local').attr('href', function(i, val) { return val.replace(regex, x); }); }); } </script> I want to be able to dynamically replace whatever the current subDomain string is, e.g., user1 with the option value I select from my form.
This script may not be elegant, but it works to replace a static string in the url. What I'm trying to do is replace everything between "http://" and ".", but try as I may, I cannot figure out the proper regex to do so.
$(document).readywithin yourgetvalfunction. It should be wrapping it if anything.http://subDomain.mysite.comshould becomehttp://user1.mysite.com?