0

I would like to add checkbox values to URL without refresh / redirect the page. I have my filter that works perfectly with AJAX but this is not SEO friendly because the URL doesn't change while changing the checkboxes.

So if i have for example a checkboxes like these:

<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>

And URL is now www.mydomain.com/transport.php? And jQuery should append vehicles=Bike,Car Or just one of these If checkbox isn't checkhed the value to append would just be ''

I appreciate any help!

1 Answer 1

2

You can use the window.location.hash property, would be something like this:

<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>

<script>
$('input[type=checkbox').click(function(){
        window.location.hash = 'vehicles=' + $(this).val();
    });
</script>

I am assuming you have the url like www.mydomain.com/transport.php?

Sign up to request clarification or add additional context in comments.

1 Comment

This was exactly what i was looking for the website is ready, thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.