Basically, if I’m at: http://example.com/content/connect/152, I want to find out if “connect” is present in the url and then set the selected value of a menu to something specific… (The url could also be something like http://example.com/content/connections, in which case, it should still match…)
This is what I’ve been trying, which, clearly isn’t working….
var path = window.location.pathname;
if(path).match(/^connect) {
$("#myselect").val('9');
} else {
$("#myselect").val('0');
}
Since connect can be anywhere in your URL there is no need to add the ^
try :
this assume that you want a “/” right before a connect