jquery - Javascript redirect to page and append text -
i have forum can filter 'category1', 'category2', or 'all'
now have dropdown has 3 options. javascript/jquery i'm doing this:
$('#dropdown').on('change', function () { if ($('#dropdown').val() == 'category1') { window.location.href += "/cat1"; } else if ($('#dropdown').val() == 'category2') { window.location.href += "/cat2"; } else { window.location.replace(window.location.href); } });
the problem code above first change goes correctly say: "website/foo/bar/cat1" when change dropdown again cat2 goes , fails: "website/foo/bar/cat1/cat2"
is there anyway can keep same url everytime change dropdown value? theres catch though. "website/foo/bar/" has "bar" can such this: "website/foo/something/" or "website/foo/else/"
when add url += appending existing url.
var url = "http://example.com/foo/bar/" $('#dropdown').on('change', function () { if ($('#dropdown').val() == 'category1') { window.location.href = url + "cat1"; } else if ($('#dropdown').val() == 'category2') { window.location.href = url + "cat2"; } else { window.location.replace(window.location.href); } });
Comments
Post a Comment