-1

Here is My Checkbox code. Checkbox value get: http://mydomainsss.com/men.html?band_colour=131

<span class="check-box">
    <input type="checkbox" name="vehicle" class="filtercheckbox" value="<?php echo $this->urlEscape($_item->getUrl())?>" />
</span>

Here is my Jquery Code:

<script type="text/javascript">
jQuery('input[type=checkbox').click(function(){

      window.location.hash = jQuery(this).val();
    });
</script>

This code simple change URL like http://mydomainsss.com/men.html#http://mydomainsss.com.com/men.html?band_colour=131

but I want to redirect to http://mydomainsss.com/men.html?band_colour=131 without page reload. so can anyone help me?

3 Answers3

0

Just use hash in the value of the input, not whole URL.

jQuery('input[type=checkbox').change(function(){
  window.location.hash = jQuery(this).val();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="check-box">
  <input type="checkbox" name="vehicle" class="filtercheckbox" value="#something" />
</span>
Rohit Sharma
  • 3,304
  • 2
  • 19
  • 34
0

Just use ways below instead of use .hash

window.location.replace(jQuery(this).val());

or
window.location.href = jQuery(this).val();

or Jquery
$(location).attr('href', jQuery(this).val())

This way will redirect to new link.

UPDATE: I used to think you want to REDIRECT this page.

If you just want to change the url, please research html5 function

history.pushState


If you want to redirect without pageload, you have to research Angular, React, Backbone...

Or use ajax page load libarry such as: pjax, smoothState.js to load some content without page reload.


Thanks for unvote :(

vinhphon
  • 11
  • 3
-1

Change window.location.hash to window.location.href:

<script type="text/javascript">
  jQuery('input[type=checkbox').click(function(){
    window.location.href = jQuery(this).val();
  });
</script>
Rohit Sharma
  • 3,304
  • 2
  • 19
  • 34
Linards Kalvans
  • 479
  • 2
  • 8